DifferenceInDifferences.plot#
- DifferenceInDifferences.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 isHDI_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_transformis accepted alongsidebbox_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:
Notes
Internally, this function dispatches to either _bayesian_plot or _ols_plot depending on the model type. The
kind,ci_kind,ci_prob, andnum_samplesparameters are passed through to the underlying plotting methods (e.g. forplot_xY()).Legend handling and ``plot_xY`` return types:
plot_xY()returns(Line2D, PolyCollection)forkind="ribbon"but(list[Line2D], None)forkind="histogram"or"spaghetti". Subclass_bayesian_plot/_ols_plotimplementations that assemble matplotlib legends from those return values should only pack(line, patch)tuples when callingplot_xYwithkind="ribbon"(the default). Many current experiment plots always use the ribbon default and never forwardkind; if a subclass forwards non-ribbon kinds, it must build legend handles accordingly. The base class applieslegend_kwargsby 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)}, ... )