arviz.plot_autocorr(data, var_names=None, filter_vars=None, max_lag=None, combined=False, grid=None, figsize=None, textsize=None, labeller=None, ax=None, backend=None, backend_config=None, backend_kwargs=None, show=None)[source]

Bar plot of the autocorrelation function for a sequence of data.

Useful in particular for posteriors from MCMC samples which may display correlation.

data: obj

Any object that can be converted to an arviz.InferenceData object refer to documentation of arviz.convert_to_dataset() for details

var_names: list of variable names, optional

Variables to be plotted, if None all variables are plotted. Prefix the variables by ~ when you want to exclude them from the plot. Vector-value stochastics are handled automatically.

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. A la pandas.filter.

max_lag: int, optional

Maximum lag to calculate autocorrelation. Defaults to 100 or num draws, whichever is smaller.

combined: bool, default=False

Flag for combining multiple chains into a single chain. If False, chains will be plotted separately.


Number of rows and columns. Defaults to None, the rows and columns are automatically inferred.

figsize: tuple

Figure size. If None it will be defined automatically. Note this is not used if ax is supplied.

textsize: float

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

labellerlabeller instance, optional

Class providing the method make_label_vert to generate the labels in the plot titles. Read the Label guide for more details and usage examples.

ax: numpy array-like of matplotlib axes or bokeh figures, optional

A 2D array of locations into which to plot the densities. If not supplied, Arviz will create its own array of plot areas (and return it).

backend: str, optional

Select plotting backend {“matplotlib”,”bokeh”}. Default “matplotlib”.

backend_config: dict, optional

Currently specifies the bounds to use for bokeh axes. Defaults to value set in rcParams.

backend_kwargs: dict, optional

These are kwargs specific to the backend being used, passed to matplotlib.pyplot.subplots() or bokeh.plotting.figure().

show: bool, optional

Call backend show function.

axes: matplotlib axes or bokeh figures

See also


Compute autocovariance estimates for every lag for the input array.


Compute autocorrelation using FFT for every lag for the input array.


Plot default autocorrelation

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

Plot subset variables by specifying variable name exactly

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

Combine chains by variable and select variables by excluding some with partial naming

>>> az.plot_autocorr(data, var_names=['~thet'], filter_vars="like", combined=True)

Specify maximum lag (x axis bound)

>>> az.plot_autocorr(data, var_names=['mu', 'tau'], max_lag=200, combined=True)