arviz_plots.plot_ridge

Contents

arviz_plots.plot_ridge#

arviz_plots.plot_ridge(dt, var_names=None, filter_vars=None, group='posterior', coords=None, sample_dims=None, combined=True, ridge_height=0.9, labels=None, shade_label=None, plot_collection=None, backend=None, labeller=None, aes_by_visuals=None, visuals=None, stats=None, **pc_kwargs)[source]#

Plot 1D marginal densities in a single plot, akin to a forest plot.

Parameters:
dtxarray.DataTree or dict of {strxarray.DataTree}

Input data. In case of dictionary input, the keys are taken to be model names. In such cases, a dimension “model” is generated and can be used to map to aesthetics.

plot_ridge uses the dimension “column” (creating it if necessary) to generate the grid then adds the intervals+point estimates to its “ridge” coordinate and labels to its “labels” coordinates. The data used to plot is then the subset column="ridge".

var_namesstr or list of str, optional

One or more variables to be plotted. Prefix the variables by ~ when you want to exclude them from the plot.

filter_vars{None, “like”, “regex”}, default None

If None, interpret var_names as the real variables names. If “like”, interpret var_names as substrings of the real variables names. If “regex”, interpret var_names as regular expressions on the real variables names.

groupstr, default “posterior”

Group to be plotted.

coordsdict, optional
sample_dimsstr or sequence of hashable, optional

Dimensions to reduce unless mapped to an aesthetic. Defaults to rcParams["data.sample_dims"]

combinedbool, default True

Whether to plot intervals for each chain or not. Ignored when the “chain” dimension is not present.

ridge_heightfloat, default 0.9

Regulates the height of the ridge (tallest peak in the ridge). 1 or lower means no overlap (with combined=True), higher than 1 means some overlap might occur. See the “Notes” section for more info on vertical spacing.

labelssequence of str, optional

Sequence with the dimensions to be labelled in the plot. By default all dimensions except “chain” and “model” (if present). The order of labels is ignored, only elements being present in it matters. It can include the special “__variable__” indicator, and does so by default.

shade_labelstr, default None

Element of labels that should be used to add shading horizontal strips to the plot. Note that labels and credible intervals are plotted in different plots. The shading is applied to both plots, and the spacing between them is set to 0 if possible, which is not always the case (one notable example being matplotlib’s constrained layout).

plot_collectionPlotCollection, optional
backend{“matplotlib”, “bokeh”}, optional
labellerlabeller, optional
aes_by_visualsmapping of {strsequence of str or False}, optional

Mapping of visuals to aesthetics that should use their mapping in plot_collection when plotted. Valid keys are the same as for visuals except “ticklabels” which doesn’t apply.

By default, aesthetic mappings are generated for: y, alpha, overlay and color (if multiple models are present). All aesthetic mappings but alpha are applied to both the ridge and ridge base; overlay is applied to labels; and both overlay and alpha are applied to the shade.

“overlay” is a dummy aesthetic to trigger looping over variables and/or dimensions using all aesthetics in every iteration. “alpha” gets two values (0, 0.3) in order to trigger the alternate shading effect.

visualsmapping of {strmapping or False}, optional

Valid keys are:

statsmapping, optional

Valid keys are:

  • dist -> passed to kde

pc_kwargsmapping

Passed to arviz_plots.PlotCollection.grid

Returns:
PlotCollection

See also

plot_forest

Plot 1D marginal credible intervals in a single plot

Notes

The separation between variables and all its coordinate values is set to 1. The only two exceptions to this are the dimensions named “chain” and “model” in case they are present, which get a smaller spacing to give a sense of grouping among visual elements that only differ on their chain or model id.

Examples

The following example focuses on behaviour specific to plot_ridge. For a general introduction to batteries-included functions like this one and common usage examples see Introduction to batteries-included plots

This example shows a ridge plot for single model, with color mapped to a given variable (which is also applied to the labels) and alternate shading per school. To ensure the shading looks continuous, we’ll specify we don’t want to use a constrained layout (set by the “arviz-variat” theme) and to avoid having the labels too squished we’ll set the width_ratios for create_plotting_grid via pc_kwargs.

>>> from arviz_plots import plot_ridge, style
>>> from arviz_base import load_arviz_data
>>> style.use("arviz-variat")
>>> non_centered = load_arviz_data('non_centered_eight')
>>> pc = plot_ridge(
>>>     non_centered,
>>>     var_names=["theta", "mu", "theta_t", "tau"],
>>>     aes={"color": ["__variable__"]},
>>>     figure_kwargs={"width_ratios": [1, 2], "layout": "none"},
>>>     aes_by_visuals={"labels": ["color"]},
>>>     shade_label="school",
>>> )
../../_images/arviz_plots-plot_ridge-1.png

For more examples see below