arviz.plot_trace

arviz.plot_trace(data, var_names=None, coords=None, divergences='bottom', figsize=None, textsize=None, lines=None, combined=False, plot_kwargs=None, fill_kwargs=None, rug_kwargs=None, hist_kwargs=None, trace_kwargs=None)[source]

Plot distribution (histogram or kernel density estimates) and sampled values.

If divergences data is available in sample_stats, will plot the location of divergences as dashed vertical lines.

Parameters
dataobj

Any object that can be converted to an az.InferenceData object Refer to documentation of az.convert_to_dataset for details

var_nameslist of variable names

Variables to be plotted, two variables are required.

coordsmapping, optional

Coordinates of var_names to be plotted. Passed to Dataset.sel

divergences{“bottom”, “top”, None, False}

Plot location of divergences on the traceplots. Options are “bottom”, “top”, or False-y.

figsizefigure size tuple

If None, size is (12, variables * 2)

textsize: float

Text size scaling factor for labels, titles and lines. If None it will be autoscaled based on figsize.

linestuple

Tuple of (var_name, {‘coord’: selection}, [line, positions]) to be overplotted as vertical lines on the density and horizontal lines on the trace.

combinedbool

Flag for combining multiple chains into a single line. If False (default), chains will be plotted separately.

plot_kwargsdict

Extra keyword arguments passed to arviz.plot_dist. Only affects continuous variables.

fill_kwargsdict

Extra keyword arguments passed to arviz.plot_dist. Only affects continuous variables.

rug_kwargsdict

Extra keyword arguments passed to arviz.plot_dist. Only affects continuous variables.

hist_kwargsdict

Extra keyword arguments passed to arviz.plot_dist. Only affects discrete variables.

trace_kwargsdict

Extra keyword arguments passed to plt.plot

Returns
——-
axesmatplotlib axes

Examples

Plot a subset variables

>>> import arviz as az
>>> data = az.load_arviz_data('non_centered_eight')
>>> coords = {'theta_t_dim_0': [0, 1], 'school':['Lawrenceville']}
>>> az.plot_trace(data, var_names=('theta_t', 'theta'), coords=coords)
../_images/arviz-plot_trace-1.png

Combine all chains into one distribution and trace

>>> coords = {'theta_t_dim_0': [0, 1], 'school':['Lawrenceville']}
>>> az.plot_trace(data, var_names=('theta_t', 'theta'), coords=coords, combined=True)
../_images/arviz-plot_trace-2.png

Plot reference lines against distribution and trace

>>> lines = (('theta_t',{'theta_t_dim_0':0}, [-1]),)
>>> coords = {'theta_t_dim_0': [0, 1], 'school':['Lawrenceville']}
>>> az.plot_trace(data, var_names=('theta_t', 'theta'), coords=coords, lines=lines)
../_images/arviz-plot_trace-3.png