arviz_plots.plot_dist

Contents

arviz_plots.plot_dist#

arviz_plots.plot_dist(dt, var_names=None, filter_vars=None, group='posterior', coords=None, sample_dims=None, kind=None, point_estimate=None, ci_kind=None, ci_prob=None, plot_collection=None, backend=None, labeller=None, aes_map=None, plot_kwargs=None, stats_kwargs=None, pc_kwargs=None)[source]#

Plot 1D marginal densities in the style of John K. Kruschke’s book.

Generate facetted plots with: a graphical representation of 1D marginal densities (as KDE, histogram, ECDF or dotplot), a credible interval and a point estimate.

Parameters:
dtdatatree.DataTree or dict of {strdatatree.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.

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"]

kind{“kde”, “hist”, “dot”, “ecdf”}, optional

How to represent the marginal density. Defaults to rcParams["plot.density_kind"]

point_estimate{“mean”, “median”, “mode”}, optional

Which point estimate to plot. Defaults to rcParams["plot.point_estimate"]

ci_kind{“eti”, “hdi”}, optional

Which credible interval to use. Defaults to rcParams["stats.ci_kind"]

ci_probfloat, optional

Indicates the probability that should be contained within the plotted credible interval. Defaults to rcParams["stats.ci_prob"]

plot_collectionPlotCollection, optional
backend{“matplotlib”, “bokeh”}, optional
labellerlabeller, optional
aes_mapmapping of {strsequence of str}, optional

Mapping of artists to aesthetics that should use their mapping in plot_collection when plotted. Valid keys are the same as for plot_kwargs.

With a single model, no aesthetic mappings are generated by default, each variable+coord combination gets a plot but they all look the same, unless there are user provided aesthetic mappings. With multiple models, plot_dist maps “color” and “y” to the “model” dimension.

By default, all aesthetics but “y” are mapped to the density representation, and if multiple models are present, “color” and “y” are mapped to the credible interval and the point estimate.

When “point_estimate” key is provided but “point_estimate_text” isn’t, the values assigned to the first are also used for the second.

plot_kwargsmapping of {strmapping or False}, optional

Valid keys are:

  • One of “kde”, “ecdf”, “dot” or “hist”, matching the kind argument.

  • credible_interval -> passed to line_x

  • point_estimate -> passed to scatter_x

  • point_estimate_text -> passed to point_estimate_text

  • title -> passed to labelled_title

  • remove_axis -> not passed anywhere, can only be False to skip calling this function

stats_kwargsmapping, optional

Valid keys are:

  • density -> passed to kde, ecdf, …

  • credible_interval -> passed to eti or hdi

  • point_estimate -> passed to mean, median or mode

pc_kwargsmapping

Passed to arviz_plots.PlotCollection.wrap

Returns:
PlotCollection

Examples

The following examples focus on behaviour specific to plot_dist. For a general introduction to batteries-included functions like this one and common usage examples see Introduction to batteries-included plots in arviz_plots

Default plot_dist for a single model:

>>> from arviz_plots import plot_dist, style
>>> style.use("arviz-clean")
>>> from arviz_base import load_arviz_data
>>> centered = load_arviz_data('centered_eight')
>>> non_centered = load_arviz_data('non_centered_eight')
>>> pc = plot_dist(centered)
../../_images/arviz_plots-plot_dist-1.png

Default plot_dist for multiple models:

>>> pc = plot_dist(
>>>     {"centered": centered, "non centered": non_centered},
>>>     coords={"school": ["Choate", "Deerfield", "Hotchkiss"]},
>>> )
>>> pc.add_legend("model")
../../_images/arviz_plots-plot_dist-2.png

We can also manually map the color to the variable, and have the mapping apply to the title too instead of only the density representation:

>>> pc = plot_dist(
>>>     non_centered,
>>>     coords={"school": ["Choate", "Deerfield", "Hotchkiss"]},
>>>     pc_kwargs={"aes": {"color": ["__variable__"]}},
>>>     aes_map={"title": ["color"]},
>>> )
../../_images/arviz_plots-plot_dist-3.png