mgplot.revision_plot

revision_plot.py

Plot ABS revisions to estimates over time. This is largely a wrapper around the line_plot function, with some default settings and minimal checks on the data.

 1"""
 2revision_plot.py
 3
 4Plot ABS revisions to estimates over time.  This is largely
 5a wrapper around the line_plot function, with some
 6default settings and minimal checks on the data.
 7"""
 8
 9# --- imports
10from matplotlib.pyplot import Axes
11from pandas import DataFrame
12
13from mgplot.utilities import check_clean_timeseries
14from mgplot.line_plot import LINE_KW_TYPES, line_plot
15from mgplot.kw_type_checking import validate_kwargs, validate_expected
16from mgplot.kw_type_checking import report_kwargs
17from mgplot.settings import DataT
18from mgplot.kw_type_checking import ExpectedTypeDict
19from mgplot.keyword_names import (
20    PLOT_FROM,
21    ANNOTATE,
22    ANNOTATE_COLOR,
23    ROUNDING,
24)
25
26
27# --- constants
28REVISION_KW_TYPES: ExpectedTypeDict = LINE_KW_TYPES
29validate_expected(REVISION_KW_TYPES, "revision_plot")
30
31
32# --- functions
33def revision_plot(data: DataT, **kwargs) -> Axes:
34    """
35    Plot the revisions to ABS data.
36
37    Arguments
38    data: pd.DataFrame - the data to plot, the DataFrame has a
39        column for each data revision
40    kwargs - additional keyword arguments for the line_plot function.
41    """
42
43    # --- check the kwargs and data
44    me = "revision_plot"
45    report_kwargs(called_from=me, **kwargs)
46    kwargs = validate_kwargs(REVISION_KW_TYPES, me, **kwargs)
47
48    data = check_clean_timeseries(data, me)
49
50    # --- additional checks
51    if not isinstance(data, DataFrame):
52        print(
53            f"{me} requires a DataFrame with columns for each revision, "
54            "not a Series or other type."
55        )
56
57    # --- critical defaults
58    kwargs[PLOT_FROM] = kwargs.get(PLOT_FROM, -15)
59    kwargs[ANNOTATE] = kwargs.get(ANNOTATE, True)
60    kwargs[ANNOTATE_COLOR] = kwargs.get(ANNOTATE_COLOR, "black")
61    kwargs[ROUNDING] = kwargs.get(ROUNDING, 3)
62
63    # --- plot
64    axes = line_plot(data, **kwargs)
65
66    return axes
REVISION_KW_TYPES: mgplot.kw_type_checking.ExpectedTypeDict = {'ax': (<class 'matplotlib.axes._axes.Axes'>, <class 'NoneType'>), 'style': (<class 'str'>, <class 'collections.abc.Sequence'>, (<class 'str'>,)), 'width': (<class 'float'>, <class 'int'>, <class 'collections.abc.Sequence'>, (<class 'float'>, <class 'int'>)), 'color': (<class 'str'>, <class 'collections.abc.Sequence'>, (<class 'str'>,)), 'alpha': (<class 'float'>, <class 'collections.abc.Sequence'>, (<class 'float'>,)), 'drawstyle': (<class 'str'>, <class 'collections.abc.Sequence'>, (<class 'str'>,), <class 'NoneType'>), 'marker': (<class 'str'>, <class 'collections.abc.Sequence'>, (<class 'str'>,), <class 'NoneType'>), 'markersize': (<class 'float'>, <class 'collections.abc.Sequence'>, (<class 'float'>,), <class 'int'>, <class 'NoneType'>), 'dropna': (<class 'bool'>, <class 'collections.abc.Sequence'>, (<class 'bool'>,)), 'annotate': (<class 'bool'>, <class 'collections.abc.Sequence'>, (<class 'bool'>,)), 'rounding': (<class 'collections.abc.Sequence'>, (<class 'bool'>, <class 'int'>), <class 'int'>, <class 'bool'>, <class 'NoneType'>), 'fontsize': (<class 'collections.abc.Sequence'>, (<class 'str'>, <class 'int'>, <class 'float'>), <class 'str'>, <class 'int'>, <class 'float'>), 'fontname': (<class 'str'>, <class 'collections.abc.Sequence'>, (<class 'str'>,)), 'rotation': (<class 'int'>, <class 'float'>, <class 'collections.abc.Sequence'>, (<class 'int'>, <class 'float'>)), 'annotate_color': (<class 'str'>, <class 'collections.abc.Sequence'>, (<class 'str'>,), <class 'bool'>, <class 'collections.abc.Sequence'>, (<class 'bool'>,), <class 'NoneType'>), 'plot_from': (<class 'int'>, <class 'pandas._libs.tslibs.period.Period'>, <class 'NoneType'>), 'label_series': (<class 'bool'>, <class 'collections.abc.Sequence'>, (<class 'bool'>,), <class 'NoneType'>)}
def revision_plot(data: ~DataT, **kwargs) -> matplotlib.axes._axes.Axes:
34def revision_plot(data: DataT, **kwargs) -> Axes:
35    """
36    Plot the revisions to ABS data.
37
38    Arguments
39    data: pd.DataFrame - the data to plot, the DataFrame has a
40        column for each data revision
41    kwargs - additional keyword arguments for the line_plot function.
42    """
43
44    # --- check the kwargs and data
45    me = "revision_plot"
46    report_kwargs(called_from=me, **kwargs)
47    kwargs = validate_kwargs(REVISION_KW_TYPES, me, **kwargs)
48
49    data = check_clean_timeseries(data, me)
50
51    # --- additional checks
52    if not isinstance(data, DataFrame):
53        print(
54            f"{me} requires a DataFrame with columns for each revision, "
55            "not a Series or other type."
56        )
57
58    # --- critical defaults
59    kwargs[PLOT_FROM] = kwargs.get(PLOT_FROM, -15)
60    kwargs[ANNOTATE] = kwargs.get(ANNOTATE, True)
61    kwargs[ANNOTATE_COLOR] = kwargs.get(ANNOTATE_COLOR, "black")
62    kwargs[ROUNDING] = kwargs.get(ROUNDING, 3)
63
64    # --- plot
65    axes = line_plot(data, **kwargs)
66
67    return axes

Plot the revisions to ABS data.

Arguments data: pd.DataFrame - the data to plot, the DataFrame has a column for each data revision kwargs - additional keyword arguments for the line_plot function.