Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time series plots #31

Merged
merged 45 commits into from
Nov 11, 2024
Merged

Time series plots #31

merged 45 commits into from
Nov 11, 2024

Conversation

alondmnt
Copy link
Contributor

@alondmnt alondmnt commented Sep 3, 2024

Description

This PR adds various time series plots that are designed to be:

  • Standardised
  • Reusable
  • Customisable
  • Composable

The use cases currently focus on diet, CGM and sleep, but these functions can be adapted to application data and other time series. Some of the diet plots may be refactored to be more generalised in the future.

See also: https://github.com/PhenoAI/pheno-examples/pull/15

New features

  • timeseries_plots.py
    • TimeSeriesFigure: class to handle mult-track time series plots more easily, by managing their axes together.
    • plot_events_bars: general purpose function for events.
    • plot_events_fill: general purpose function for events.
  • diet_plots.py
    • plot_nutrient_bars: simple time plot of stacked bars of fields, separated according to units.
    • plot_nutrient_lollipop: fancy time plot of pie charts of nutrients.
    • plot_meals_hbars: time plot of meal content by food categories.
    • plot_diet_cgm_sleep: combines almost all of the above together.
  • sleep_plots.py
    • plot_sleep: re-implemented with the above functions.

TODOs

  • Add plot examples (and the corresponding data) to pheno-utils.
  • Make other existing time plots compatible with TimeSeriesFigure.

Examples

3 diet plots in 1 figure

g = TimeSeriesFigure(figsize=(14, 7))

time_range = ('2021-04-05 6:00', '2021-04-06 0:00')
# Each call to the plot() methods adds a new time-synced subplot to the figure.
# A plot function only needs to have an `ax` arg to support the TimeSeriesFigure.
g.plot(plot_nutrient_lollipop, events_df, size_scale=15, time_range=time_range,
       name='diet_pie')
g.plot(plot_meals_hbars, events_df, time_range=time_range,
       name='diet_meals', height=2)
g.plot(plot_nutrient_bars, events_df, label=None, time_range=time_range,
       name='diet_bars', n_axes=3)
g.set_axis_padding(0.07)

image

diet X cgm X sleep

image

updated sleep plot

image

@alondmnt alondmnt changed the title Tme Series Plots Time Series Plots Sep 3, 2024
@alondmnt alondmnt changed the title Time Series Plots Time series plots Sep 3, 2024
@MariaGorodetski MariaGorodetski added this pull request to the merge queue Nov 11, 2024
Merged via the queue into master with commit ff301ee Nov 11, 2024
2 checks passed
@alondmnt alondmnt deleted the dev-timeseries-plot branch November 12, 2024 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants