arviz_plots.plot_trace_dist

Contents

arviz_plots.plot_trace_dist#

arviz_plots.plot_trace_dist(dt, var_names=None, filter_vars=None, group='posterior', coords=None, sample_dims=None, compact=True, combined=False, kind=None, plot_collection=None, backend=None, labeller=None, aes_map=None, plot_kwargs=None, stats_kwargs=None, pc_kwargs=None)[source]#

Plot 1D marginal distributions and iteration versus sampled values.

Parameters:
dtdatatree.DataTree

Input data

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”}, optional, default=None

If None (default), 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.

sample_dimsstr or sequence of hashable, optional

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

compactbool, default True

Plot multidimensional variables in a single plot.

combinedbool, default False

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

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

How to represent the marginal distribution.

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

Mapping of artists to aesthetics that should use their mapping in plot_collection when plotted. The defaults depend on the combination of compact and combined, see the examples section for an illustrated description. Valid keys are the same as for plot_kwargs.

plot_kwargsmapping of {strmapping or False}, optional

Valid keys are:

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

  • “trace” -> passed to line

  • “divergence” -> passed to trace_rug

  • “label” -> labelled_x and labelled_y

  • “ticklabels” -> ticklabel_props

  • “xlabel_trace” -> labelled_x

  • 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, …

pc_kwargsmapping

Passed to arviz_plots.PlotCollection

Returns:
PlotCollection

Examples

The following examples focus on behaviour specific to plot_trace_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_trace_dist (compact=True and combined=False). In this case, the multiple coordinate values are overlaid on the same plot for multidimensional values; by default, the color is mapped to all dimensions of each variable (but sample_dims) to allow distinguising the different coordinate values.

As combined=False each chain is also being plotted, overlaying them on their corresponding plots; as the color property is already taken, the chain information is encoded in the linestyle as default.

Both mappings are applied to the trace and dist elements.

>>> from arviz_plots import plot_trace_dist, style
>>> style.use("arviz-clean")
>>> from arviz_base import load_arviz_data
>>> centered = load_arviz_data('centered_eight')
>>> coords = {"school": ["Choate", "Deerfield", "Hotchkiss"]}
>>> pc = plot_trace_dist(centered, coords=coords, compact=True, combined=False)
>>> pc.add_legend("school")
../../_images/arviz_plots-plot_trace_dist-1.png

plot_trace_dist with compact=True and combined=True. The aesthetic mappings stay the same as in the previous case, but now the linestyle property mapping is only taken into account for the trace as in the left column, we use the data from all chains to generate a single distribution representation for each variable+coordinate value combination.

Similarly to the first case, this default and now only mapping is applied to both the trace and the dist elements.

>>> pc = plot_trace_dist(centered, coords=coords, compact=True, combined=True)
>>> pc.add_legend("school")
../../_images/arviz_plots-plot_trace_dist-2.png

When compact=False, each variable and coordinate value gets its own plot, and so the color property is no longer used to encode this information. Instead, it is now used to encode the chain information.

>>> pc = plot_trace_dist(centered, coords=coords, compact=False, combined=False)
../../_images/arviz_plots-plot_trace_dist-3.png

Similarly to the other combined=True case, the aesthetics stay the same as with combined=False, but they are ignored by default when plotting on the left column.

>>> pc = plot_trace_dist(centered, coords=coords, compact=False, combined=True)
>>> pc.add_legend("chain")
../../_images/arviz_plots-plot_trace_dist-4.png