macrosynergy.visuals.lineplot#
A subclass inheriting from macrosynergy.visuals.plotter.Plotter, designed to plot time series data on a line plot.
- class LinePlot(df, cids=None, xcats=None, metrics=None, intersect=False, tickers=None, blacklist=None, start=None, end=None, *args, **kwargs)[source]#
Bases:
Plotter
Class for plotting time series data on a line plot. Inherits from macrosynergy.visuals.plotter.Plotter.
- Parameters:
df (DataFrame) – A DataFrame with the following columns: ‘cid’, ‘xcat’, ‘real_date’, and at least one metric from - ‘value’, ‘grading’, ‘eop_lag’, or ‘mop_lag’.
cids (List[str]) – A list of cids to select from the DataFrame. If None, all cids are selected.
xcats (List[str]) – A list of xcats to select from the DataFrame. If None, all xcats are selected.
metrics (List[str]) – A list of metrics to select from the DataFrame. If None, all metrics are selected.
start_date (str) – ISO-8601 formatted date. Select data from this date onwards. If None, all dates are selected.
end_date (str) – ISO-8601 formatted date. Select data up to and including this date. If None, all dates are selected.
- plot(metric='value', compare_series=None, figsize=(12, 8), aspect=1.618, height=0.8, grid=True, x_axis_label=None, y_axis_label=None, axis_fontsize=12, ax_hline=None, ax_vline=None, title=None, title_fontsize=16, title_xadjust=0.5, title_yadjust=1.05, legend=True, legend_labels=None, legend_title=None, legend_loc='best', legend_fontsize=14, legend_ncol=1, legend_bbox_to_anchor=None, legend_frame=True, show=True, save_to_file=None, dpi=300, return_figure=False, on_axis=None, *args, **kwargs)[source]#
Plot the time series data on a line plot.
- Parameters:
metric (str) – The metric to plot. Default is ‘value’.
compare_series (Optional[str]) – A ticker (cid_xcat) to compare the metric against. Default is None.
figsize (Tuple[Number, Number]) – The size of the figure. Default is (12, 8).
aspect (Number) – The aspect ratio of the figure. Default is 1.618.
height (Number) – The height of the figure. Default is 0.8.
grid (bool) – Whether to show a grid on the plot. Default is True.
x_axis_label (Optional[str]) – The label for the x-axis. Default is None.
y_axis_label (Optional[str]) – The label for the y-axis. Default is None.
axis_fontsize (int) – The fontsize for the axis labels. Default is 12.
ax_hline (Optional[Union[Number, List[Number]]]) – A horizontal line to add to the plot. The numeric value(s) of the x-axis where the line should be drawn. Default is None.
ax_vline (Optional[Union[str, List[str]]]) – A vertical line to add to the plot. The date(s) where the line should be drawn. Default is None.
title (Optional[str]) – The title of the plot. Default is None.
title_fontsize (int) – The fontsize of the title. Default is 16.
title_xadjust (Number) – The x-adjustment of the title. Default is 0.5.
title_yadjust (Number) – The y-adjustment of the title. Default is 1.05.
legend (bool) – Whether to show a legend on the plot. Default is True.
legend_labels (Optional[List[str]]) – The labels for the legend. Default is None.
legend_title (Optional[str]) – The title of the legend. Default is None.
legend_loc (Optional[str]) – The location of the legend. Default is ‘best’.
legend_fontsize (int) – The fontsize of the legend. Default is 14.
legend_ncol (int) – The number of columns in the legend. Default is 1.
legend_bbox_to_anchor (Optional[Tuple[Number, Number]]) – The bbox_to_anchor of the legend. Default is None.
legend_frame (bool) – Whether to show a frame around the legend. Default is True.
show (bool) – Whether to show the plot. Default is True.
save_to_file (Optional[str]) – The path to save the plot to. Default is None.
dpi (int) – The DPI of the saved plot. Default is 300.
return_figure (bool) – Whether to return the figure. Default is False.
on_axis (Optional[plt.Axes]) – An axis to plot on. Default is None.
*args – Additional arguments.
**kwargs – Additional keyword arguments.