RegressionDiscontinuity.plot#

RegressionDiscontinuity.plot(kind='ribbon', ci_kind='hdi', ci_prob=0.94, num_samples=50, *args, show=True, legend_kwargs=None, **kwargs)#

Plot the model.

Parameters:
  • kind (Literal['ribbon', 'histogram', 'spaghetti']) – Type of visualization. Default is “ribbon”.

  • ci_kind (Literal['hdi', 'eti']) – Type of interval for ribbon plots. Default is “hdi”.

  • ci_prob (float) – The size of the credible interval. Default is HDI_PROB.

  • num_samples (int) – Number of posterior samples to plot for spaghetti visualization. Default is 50.

  • show (bool) – Whether to automatically display the plot. Defaults to True. Set to False if you want to modify the figure before displaying it.

  • legend_kwargs (dict[str, Any] | None) –

    Keyword arguments to adjust legend placement and styling. The existing legend is modified in place so that custom handles (e.g. (Line2D, PolyCollection) tuples) are fully preserved.

    Supported keys: loc, bbox_to_anchor, fontsize, frameon, title. bbox_transform is accepted alongside bbox_to_anchor.

  • *args (Any) – Additional positional arguments passed to _bayesian_plot or _ols_plot.

  • **kwargs (Any) – Additional keyword arguments passed to _bayesian_plot or _ols_plot. Can include deprecated interval and hdi_prob for backward compatibility.

Returns:

Tuple of figure and axes objects (format depends on experiment type).

Return type:

tuple

Notes

Internally, this function dispatches to either _bayesian_plot or _ols_plot depending on the model type. The kind, ci_kind, ci_prob, and num_samples parameters are passed through to the underlying plotting methods (e.g. for plot_xY()).

Legend handling and ``plot_xY`` return types: plot_xY() returns (Line2D, PolyCollection) for kind="ribbon" but (list[Line2D], None) for kind="histogram" or "spaghetti". Subclass _bayesian_plot / _ols_plot implementations that assemble matplotlib legends from those return values should only pack (line, patch) tuples when calling plot_xY with kind="ribbon" (the default). Many current experiment plots always use the ribbon default and never forward kind; if a subclass forwards non-ribbon kinds, it must build legend handles accordingly. The base class applies legend_kwargs by mutating an existing legend in place, which preserves whatever handle objects the subclass attached (including tuple handles used for ribbon mean+band).

Examples

Move the legend outside the plot area to avoid overlap:

>>> fig, ax = result.plot(
...     show=False,
...     legend_kwargs={"loc": "upper left", "bbox_to_anchor": (1.04, 1)},
... )