arviz.plot_posterior(data, var_names=None, coords=None, figsize=None, textsize=None, credible_interval=0.94, round_to=1, point_estimate='mean', rope=None, ref_val=None, kind='kde', bw=4.5, bins=None, ax=None, **kwargs)[source]

Plot Posterior densities in the style of John K. Kruschke’s book.


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


Figure size. If None it will be defined automatically.

textsize: float

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

credible_intervalfloat, optional

Credible intervals. Defaults to 0.94.


Controls formatting for floating point numbers

point_estimate: str

Must be in (‘mode’, ‘mean’, ‘median’)

rope: tuple or dictionary of tuples

Lower and upper values of the Region Of Practical Equivalence. If a list is provided, its length should match the number of variables.

ref_val: float or dictionary of floats

display the percentage below and above the values in ref_val. If a list is provided, its length should match the number of variables.

kind: str

Type of plot to display (kde or hist) For discrete variables this argument is ignored and a histogram is always used.


Bandwidth scaling factor for the KDE. Should be larger than 0. The higher this number the smoother the KDE will be. Defaults to 4.5 which is essentially the same as the Scott’s rule of thumb (the default rule used by SciPy). Only works if kind == kde.

binsinteger or sequence or ‘auto’, optional

Controls the number of bins, accepts the same keywords matplotlib.hist() does. Only works if kind == hist. If None (default) it will use auto for continuous variables and range(xmin, xmax + 1) for discrete variables.


Matplotlib axes. Defaults to None.


Passed as-is to plt.hist() or plt.plot() function depending on the value of kind.

axmatplotlib axes


Show a default kernel density plot following style of John Kruschke

>>> import arviz as az
>>> data = az.load_arviz_data('centered_eight')
>>> az.plot_posterior(data)

Plot subset variables by specifying variable name exactly

>>> az.plot_posterior(data, var_names=['mu'])

Plot Region of Practical Equivalence (rope) for all distributions

>>> az.plot_posterior(data, var_names=['mu', 'theta'], rope=(-1, 1))

Plot Region of Practical Equivalence for selected distributions

>>> rope = {'mu': [{'rope': (-2, 2)}], 'theta': [{'school': 'Choate', 'rope': (2, 4)}]}
>>> az.plot_posterior(data, var_names=['mu', 'theta'], rope=rope)

Add reference lines

>>> az.plot_posterior(data, var_names=['mu', 'theta_tilde'], ref_val=0)

Show point estimate of distribution

>>> az.plot_posterior(data, var_names=['mu', 'theta_tilde'], point_estimate='mode')

Plot posterior as a histogram

>>> az.plot_posterior(data, var_names=['mu'], kind='hist')

Change size of credible interval

>>> az.plot_posterior(data, var_names=['mu'], credible_interval=.75)