mgplot.seastrend_plot
seas_trend_plot.py This module contains a function to create seasonal+trend plots. It is just a light-weight wrapper around line_plot().
1""" 2seas_trend_plot.py 3This module contains a function to create seasonal+trend plots. 4It is just a light-weight wrapper around line_plot(). 5""" 6 7# --- imports 8from typing import Final, Unpack 9from matplotlib.pyplot import Axes 10 11from mgplot.settings import DataT 12from mgplot.line_plot import line_plot, LineKwargs 13from mgplot.utilities import get_color_list, get_setting, check_clean_timeseries 14from mgplot.keyword_checking import report_kwargs, validate_kwargs 15 16# --- constants 17ME: Final[str] = "seastrend_plot" 18 19 20# --- public functions 21def seastrend_plot(data: DataT, **kwargs: Unpack[LineKwargs]) -> Axes: 22 """ 23 Publish a DataFrame, where the first column is seasonally 24 adjusted data, and the second column is trend data. 25 26 Aguments: 27 - data: DataFrame - the data to plot with the first column 28 being the seasonally adjusted data, and the second column 29 being the trend data. 30 The remaining arguments are the same as those passed to 31 line_plot(). 32 33 Returns: 34 - a matplotlib Axes object 35 """ 36 37 # Note: we will rely on the line_plot() function to do most of the work. 38 # including constraining the data to the plot_from keyword argument. 39 40 # --- check the kwargs 41 report_kwargs(caller=ME, **kwargs) 42 validate_kwargs(schema=LineKwargs, caller=ME, **kwargs) 43 44 # --- check the data 45 data = check_clean_timeseries(data, ME) 46 if len(data.columns) < 2: 47 raise ValueError("seas_trend_plot() expects a DataFrame data item with at least 2 columns.") 48 49 # --- defaults if not in kwargs 50 kwargs["color"] = kwargs.get("color", get_color_list(2)) 51 kwargs["width"] = kwargs.get("width", [get_setting("line_normal"), get_setting("line_wide")]) 52 kwargs["style"] = kwargs.get("style", ["-", "-"]) 53 kwargs["annotate"] = kwargs.get("annotate", [True, False]) 54 kwargs["rounding"] = kwargs.get("rounding", True) 55 56 # series breaks are common in seas-trend data 57 kwargs["dropna"] = kwargs.get("dropna", False) 58 59 axes = line_plot( 60 data, 61 **kwargs, 62 ) 63 64 return axes
ME: Final[str] =
'seastrend_plot'
def
seastrend_plot( data: ~DataT, **kwargs: Unpack[mgplot.LineKwargs]) -> matplotlib.axes._axes.Axes:
22def seastrend_plot(data: DataT, **kwargs: Unpack[LineKwargs]) -> Axes: 23 """ 24 Publish a DataFrame, where the first column is seasonally 25 adjusted data, and the second column is trend data. 26 27 Aguments: 28 - data: DataFrame - the data to plot with the first column 29 being the seasonally adjusted data, and the second column 30 being the trend data. 31 The remaining arguments are the same as those passed to 32 line_plot(). 33 34 Returns: 35 - a matplotlib Axes object 36 """ 37 38 # Note: we will rely on the line_plot() function to do most of the work. 39 # including constraining the data to the plot_from keyword argument. 40 41 # --- check the kwargs 42 report_kwargs(caller=ME, **kwargs) 43 validate_kwargs(schema=LineKwargs, caller=ME, **kwargs) 44 45 # --- check the data 46 data = check_clean_timeseries(data, ME) 47 if len(data.columns) < 2: 48 raise ValueError("seas_trend_plot() expects a DataFrame data item with at least 2 columns.") 49 50 # --- defaults if not in kwargs 51 kwargs["color"] = kwargs.get("color", get_color_list(2)) 52 kwargs["width"] = kwargs.get("width", [get_setting("line_normal"), get_setting("line_wide")]) 53 kwargs["style"] = kwargs.get("style", ["-", "-"]) 54 kwargs["annotate"] = kwargs.get("annotate", [True, False]) 55 kwargs["rounding"] = kwargs.get("rounding", True) 56 57 # series breaks are common in seas-trend data 58 kwargs["dropna"] = kwargs.get("dropna", False) 59 60 axes = line_plot( 61 data, 62 **kwargs, 63 ) 64 65 return axes
Publish a DataFrame, where the first column is seasonally adjusted data, and the second column is trend data.
Aguments:
- data: DataFrame - the data to plot with the first column being the seasonally adjusted data, and the second column being the trend data. The remaining arguments are the same as those passed to line_plot().
Returns:
- a matplotlib Axes object