macrosynergy.visuals.facetplot#

A subclass inheriting from macrosynergy.visuals.plotter.Plotter, designed to render a facet plot containing any number of subplots. Given that the class allows returning a matplotlib.pyplot.Figure, one can easily add any number of subplots, even the FacetPlot itself: effectively allowing for a recursive facet plot.

class FacetPlot(df=None, cids=None, xcats=None, metrics=None, intersect=False, tickers=None, blacklist=None, start=None, end=None, *args, **kwargs)[source]#

Bases: Plotter

Class for rendering a facet plot containing any number of subplots. Inherits from macrosynergy.visuals.plotter.Plotter.

Parameters :type df: Optional[DataFrame] :param df: A DataFrame with the following columns:

‘cid’, ‘xcat’, ‘real_date’, and at least one metric from - ‘value’, ‘grading’, ‘eop_lag’, or ‘mop_lag’.

Parameters:
  • cids (Optional[List[str]]) – A list of cids to select from the DataFrame. If None, all cids are selected.

  • xcats (Optional[List[str]]) – A list of xcats to select from the DataFrame. If None, all xcats are selected.

  • metrics (Optional[List[str]]) – A list of metrics to select from the DataFrame. If None, all metrics are selected.

  • intersect (bool) – if True only retains cids that are available for all xcats. Default is False.

  • tickers (Optional[List[str]]) – A list of tickers to select from the DataFrame. If None, all tickers are selected.

  • blacklist (Optional[Dict[str, List[str]]]) – cross-sections with date ranges that should be excluded from the data frame. If one cross-section has several blacklist periods append numbers to the cross-section code.

  • start (Optional[str]) – ISO-8601 formatted date string. Select data from this date onwards. If None, all dates are selected.

  • end (Optional[str]) – ISO-8601 formatted date string. Select data up to and including this date. If None, all dates are selected.

lineplot(cids=None, xcats=None, metric=None, ncols=3, attempt_square=False, cid_grid=False, xcat_grid=False, cid_xcat_grid=False, grid_dim=None, compare_series=None, share_y=False, share_x=False, interpolate=False, figsize=(16.0, 9.0), title=None, title_fontsize=22, title_xadjust=None, title_yadjust=None, ax_grid=False, ax_hline=0.0, ax_vline=None, x_axis_label=None, y_axis_label=None, axis_fontsize=12, facet_size=None, facet_titles=None, facet_title_fontsize=14, facet_title_xadjust=0.5, facet_title_yadjust=1.0, facet_xlabel=None, facet_ylabel=None, legend=True, legend_labels=None, legend_loc='lower center', legend_fontsize=12, legend_ncol=1, legend_bbox_to_anchor=None, legend_frame=True, show=True, save_to_file=None, dpi=300, return_figure=False, *args, **kwargs)[source]#

Showing a FacetPlot composed of linear plots from the data available in the FacetPlot object after initialization. Passing any of the arguments used to initialize the FacetPlot object will cause the object to be re-initialized with the new arguments, and the plot will be rendered from the new object state.

Parameters :type ncols: int :param ncols: number of columns in the grid. Default is 3. :type attempt_square: bool :param attempt_square: attempt to make the facet grid square. Ignores

ncols when True. Default is False.

Parameters:
  • cid_grid (bool) – Create the facet grid such that each facet is a cid.

  • xcat_grid (bool) – Create the facet grid such that each facet is an xcat.

  • cid_xcat_grid (bool) – Create the facet grid such that each facet is an individual ticker. Each “row” contains plots for the same cid, and each “column” would contain plots for the same xcat. Therefore, this mode does not respect the ncols or attempt_square arguments. NB: facet_titles and legend are overridden in this mode.

  • cids_mean – Used with cid_grid with a single xcat. If True, the mean of all cids for that xcat will be plotted on all charts. If False, only the specified cids will be plotted. Default is False.

  • compare_series (Optional[str]) – Used with cid_grid with a single xcat. If specified, the series specified will be plotted in each facet, as a red dashed line. This is useful for comparing a single series, such as a benchmark/average. Ensure that the comparison series is in the dataframe, and not filtered out when initializing the FacetPlot object. Default is None. NB: compare_series can only be used when the series is not removed by reduce_df() in the object initialization.

  • share_y (bool) – whether to share the y-axis across all plots. Default is True.

  • share_x (bool) – whether to share the x-axis across all plots. Default is True.

  • interpolate (bool) – if True, gaps in the time series will be interpolated. Default is False.

  • figsize (Tuple[Number, Number]) – a tuple of floats specifying the width and height of the figure. Default is (16.0, 9.0).

  • title (Optional[str]) – the title of the plot. Default is None.

  • title_fontsize (int) – the font size of the title. Default is 20.

  • title_xadjust (Optional[Number]) – the x-adjustment of the title. Default is None.

  • title_yadjust (Optional[Number]) – the y-adjustment of the title. Default is None.

  • ax_grid (bool) – whether to show the grid on the axes, applied to all plots. Default is True.

  • ax_hline (Optional[Number]) – the value of the horizontal line on the axes, applied to all plots. Default is None, meaning no horizontal line will be shown.

  • ax_vline (Optional[str]) – the value of the vertical line on the axes, applied to all plots. The value must be a ISO-8601 formatted date-string. Default is None, meaning no vertical line will be shown.

  • 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 font size of the axis labels. Default is 12.

  • facet_size (Optional[Tuple[Number, Number]]) – a tuple of floats specifying the width and height of each facet. Default is None, meaning the facet size will be inferred from the figsize argument. If specified, the figsize argument will be ignored and the figure size will be inferred from the dimensions of the facet grid and the facet size.

  • facet_titles (Optional[List[str]]) – a list of strings specifying the titles of each facet. Default is None, meaning all facets will have the full ticker, cid, or xcat as the title. If no facet_titles are required, pass an empty list - facet_titles=[].

  • facet_title_fontsize (int) – the font size of the facet titles. Default is 12.

  • facet_title_xadjust (Number) – the x-adjustment of the facet titles. Default is None.

  • facet_title_yadjust (Number) – the y-adjustment of the facet titles. Default is None.

  • facet_xlabel (Optional[str]) – The label to be used as the axis-label/title for the x-axis of each facet. Default is None, meaning no label will be shown.

  • facet_ylabel (Optional[str]) – The label to be used as the axis-label/title for the y-axis of each facet. Default is None, meaning no label will be shown.

  • facet_label_fontsize – the font size of the facet labels. Default is 12.

  • legend (bool) – Show the legend. Default is True. When using cid_xcat_grid, the legend will not be shown as it is redundant.

  • legend_labels (Optional[List[str]]) – Labels for the legend. Default is None, meaning a list identifying the various cids/xcats will be used.

  • legend_loc (Optional[str]) – Location of the legend. Default is center left. See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html for more information.

  • legend_fontsize (int) – Font size of the legend. Default is 12.

  • legend_ncol (int) – Number of columns in the legend. Default is 1.

  • legend_bbox_to_anchor (Optional[Tuple[Number, Number]]) – Bounding box for the legend. Default is (1.0, 0.5).

  • legend_frame (bool) – Show the legend frame. Default is True.

  • show (bool) – Show the plot. Default is True.

  • save_to_file (Optional[str]) – Save the plot to a file. Default is None.

  • dpi (int) – DPI of the saved image. Default is 300.

  • return_figure (bool) – Return the figure object. Default is False.