From c1d20d390cd6c23244abd41a044f69ff60b0d7a7 Mon Sep 17 00:00:00 2001 From: Tom Kingstone Date: Tue, 28 Jul 2026 11:10:16 +0100 Subject: [PATCH 1/2] make median and mean lines optional --- .../Python/src/python_toolkit/plot/diurnal.py | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/Python_Engine/Python/src/python_toolkit/plot/diurnal.py b/Python_Engine/Python/src/python_toolkit/plot/diurnal.py index 9eb2c6fe..a7d53a1e 100644 --- a/Python_Engine/Python/src/python_toolkit/plot/diurnal.py +++ b/Python_Engine/Python/src/python_toolkit/plot/diurnal.py @@ -20,6 +20,8 @@ def diurnal( series: pd.Series, ax: plt.Axes = None, period: str = "daily", + median: bool = True, + mean: bool = True, **kwargs, ) -> plt.Axes: """Plot a profile aggregated across days in the specified timeframe. @@ -31,6 +33,10 @@ def diurnal( A matplotlib Axes object. Defaults to None. period (str, optional): The period to aggregate over. Must be one of "dailyy", "weekly", or "monthly". Defaults to "daily". + median (bool, optional): + Whether to plot the median line. Default `True`. + mean (bool, optional): + Whether to plot the mean line. Default `True`. **kwargs (Dict[str, Any], optional): Additional keyword arguments to pass to the matplotlib plotting function. legend (bool, optional): @@ -43,7 +49,6 @@ def diurnal( A matplotlib Axes object. """ - if not isinstance(series.index, pd.DatetimeIndex): raise ValueError("Series passed is not datetime indexed.") @@ -183,24 +188,26 @@ def diurnal( label="_nolegend_", ) # mean/median - ax.plot( - range(len(df) + 1)[i : i + 25], - (df["mean"].tolist() + [df["mean"].values[0]])[i : i + 24] - + [(df["mean"].tolist() + [df["mean"].values[0]])[i : i + 24][0]], - c=color, - ls="-", - lw=1, - label="Average" if n == 0 else "_nolegend_", - ) - ax.plot( - range(len(df) + 1)[i : i + 25], - (df["median"].tolist() + [df["median"].values[0]])[i : i + 24] - + [(df["median"].tolist() + [df["median"].values[0]])[i : i + 24][0]], - c=color, - ls="--", - lw=1, - label="Median" if n == 0 else "_nolegend_", - ) + if mean: + ax.plot( + range(len(df) + 1)[i : i + 25], + (df["mean"].tolist() + [df["mean"].values[0]])[i : i + 24] + + [(df["mean"].tolist() + [df["mean"].values[0]])[i : i + 24][0]], + c=color, + ls="-", + lw=1, + label="Average" if n == 0 else "_nolegend_", + ) + if median: + ax.plot( + range(len(df) + 1)[i : i + 25], + (df["median"].tolist() + [df["median"].values[0]])[i : i + 24] + + [(df["median"].tolist() + [df["median"].values[0]])[i : i + 24][0]], + c=color, + ls="--", + lw=1, + label="Median" if n == 0 else "_nolegend_", + ) # format axes ax.set_xlim(0, len(df)) From 4bf1ff2fb6ad16dcd9793e606d89d089911da4f7 Mon Sep 17 00:00:00 2001 From: Tom Kingstone Date: Wed, 29 Jul 2026 14:49:14 +0100 Subject: [PATCH 2/2] make quantile_range an explicit key word argument and document it --- Python_Engine/Python/src/python_toolkit/plot/diurnal.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Python_Engine/Python/src/python_toolkit/plot/diurnal.py b/Python_Engine/Python/src/python_toolkit/plot/diurnal.py index a7d53a1e..060f1de8 100644 --- a/Python_Engine/Python/src/python_toolkit/plot/diurnal.py +++ b/Python_Engine/Python/src/python_toolkit/plot/diurnal.py @@ -2,6 +2,7 @@ import calendar import textwrap +from typing import Tuple import matplotlib.collections as mcollections import matplotlib.lines as mlines @@ -20,6 +21,7 @@ def diurnal( series: pd.Series, ax: plt.Axes = None, period: str = "daily", + quantile_range: Tuple[float, float] = (0.05, 0.95), median: bool = True, mean: bool = True, **kwargs, @@ -33,6 +35,8 @@ def diurnal( A matplotlib Axes object. Defaults to None. period (str, optional): The period to aggregate over. Must be one of "dailyy", "weekly", or "monthly". Defaults to "daily". + quantile_range (Tuple[float, float]): + The quantile range to display in a lighter (30% alpha) colour on the plot. Defaults to (0.05, 0.95). median (bool, optional): Whether to plot the median line. Default `True`. mean (bool, optional): @@ -66,7 +70,6 @@ def diurnal( raise ValueError("minmax_range must be increasing.") minmax_alpha = kwargs.pop("minmax_alpha", 0.1) - quantile_range = kwargs.pop("quantile_range", [0.05, 0.95]) if quantile_range[0] > quantile_range[1]: raise ValueError("quantile_range must be increasing.") if quantile_range[0] < minmax_range[0] or quantile_range[1] > minmax_range[1]: