From 001d8c6bcd392853c49052e58106c4df96bc5e61 Mon Sep 17 00:00:00 2001 From: alondmnt Date: Tue, 12 Nov 2024 03:09:43 +0000 Subject: [PATCH] improved: headings in docs --- nbs/06_sleep_plots.ipynb | 7 +++++++ nbs/15_timeseries_plots.ipynb | 10 +++++++++- nbs/16_diet_plots.ipynb | 15 +++++++++++++-- pheno_utils/diet_plots.py | 8 ++++++-- pheno_utils/timeseries_plots.py | 3 ++- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/nbs/06_sleep_plots.ipynb b/nbs/06_sleep_plots.ipynb index d69f80d..51d25a2 100644 --- a/nbs/06_sleep_plots.ipynb +++ b/nbs/06_sleep_plots.ipynb @@ -303,6 +303,13 @@ " " ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# How to plot sleep events and channels" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/nbs/15_timeseries_plots.ipynb b/nbs/15_timeseries_plots.ipynb index d514d21..ffd5c86 100644 --- a/nbs/15_timeseries_plots.ipynb +++ b/nbs/15_timeseries_plots.ipynb @@ -452,7 +452,7 @@ "\n", "\n", "def format_xticks(ax: plt.Axes, xticks: Iterable=None, format: str=TIME_FORMAT, **kwargs):\n", - " \"\"\" format datestrings on x axis \"\"\"\n", + " \"\"\" Format datestrings on x axis \"\"\"\n", " if xticks is None:\n", " xticks = ax.get_xticks()\n", " ax.set_xticks(xticks)\n", @@ -484,6 +484,7 @@ " unique (bool): Whether to remove duplicate rows.\n", "\n", " Returns:\n", + "\n", " pd.DataFrame: The filtered DataFrame\n", " \"\"\"\n", " if participant_id is not None:\n", @@ -837,6 +838,13 @@ " return colors" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# How to plot time series" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/nbs/16_diet_plots.ipynb b/nbs/16_diet_plots.ipynb index 7264999..99fa2cc 100644 --- a/nbs/16_diet_plots.ipynb +++ b/nbs/16_diet_plots.ipynb @@ -217,7 +217,7 @@ "\n", " Returns:\n", "\n", - " None: The function creates a lollipop plot with pie charts on the specified or newly created axis.\n", + " plt.Axes: The Matplotlib axis on which the chart was plotted.\n", " \"\"\"\n", " # Prepare the data for plotting\n", " df, grouped_nutrients = prepare_meals(\n", @@ -514,6 +514,10 @@ " alpha (float): The transparency of the bars. Default is 0.7.\n", " ax (Optional[plt.Axes]): The Matplotlib axis on which to plot the lollipop chart. If None, a new axis is created. Default is None.\n", " figsize (Tuple[float, float]): The size of the figure to create. Default is (12, 6).\n", + "\n", + " Returns:\n", + "\n", + " plt.Axes: The Matplotlib axis on which the chart was plotted.\n", " \"\"\"\n", " diet_log = format_timeseries(\n", " diet_log, participant_id, array_index,\n", @@ -636,7 +640,7 @@ "\n", " Returns:\n", "\n", - " TimeSeriesFigure: Plot.\n", + " TimeSeriesFigure: The figure object containing the plots.\n", " \"\"\"\n", " g = TimeSeriesFigure(figsize=figsize)\n", "\n", @@ -695,6 +699,13 @@ " return g" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# How to plot diet logs" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/pheno_utils/diet_plots.py b/pheno_utils/diet_plots.py index 76efc00..e43275a 100644 --- a/pheno_utils/diet_plots.py +++ b/pheno_utils/diet_plots.py @@ -179,7 +179,7 @@ def plot_nutrient_lollipop( Returns: - None: The function creates a lollipop plot with pie charts on the specified or newly created axis. + plt.Axes: The Matplotlib axis on which the chart was plotted. """ # Prepare the data for plotting df, grouped_nutrients = prepare_meals( @@ -470,6 +470,10 @@ def plot_meals_hbars( alpha (float): The transparency of the bars. Default is 0.7. ax (Optional[plt.Axes]): The Matplotlib axis on which to plot the lollipop chart. If None, a new axis is created. Default is None. figsize (Tuple[float, float]): The size of the figure to create. Default is (12, 6). + + Returns: + + plt.Axes: The Matplotlib axis on which the chart was plotted. """ diet_log = format_timeseries( diet_log, participant_id, array_index, @@ -585,7 +589,7 @@ def plot_diet_cgm_sleep( Returns: - TimeSeriesFigure: Plot. + TimeSeriesFigure: The figure object containing the plots. """ g = TimeSeriesFigure(figsize=figsize) diff --git a/pheno_utils/timeseries_plots.py b/pheno_utils/timeseries_plots.py index c540d01..879e9fe 100644 --- a/pheno_utils/timeseries_plots.py +++ b/pheno_utils/timeseries_plots.py @@ -413,7 +413,7 @@ def show(self) -> None: def format_xticks(ax: plt.Axes, xticks: Iterable=None, format: str=TIME_FORMAT, **kwargs): - """ format datestrings on x axis """ + """ Format datestrings on x axis """ if xticks is None: xticks = ax.get_xticks() ax.set_xticks(xticks) @@ -445,6 +445,7 @@ def format_timeseries( unique (bool): Whether to remove duplicate rows. Returns: + pd.DataFrame: The filtered DataFrame """ if participant_id is not None: