statsmodels.graphics.tsaplots.plot_accf_grid¶
- statsmodels.graphics.tsaplots.plot_accf_grid(x, *, varnames=None, fig=None, lags=None, negative_lags=True, alpha=0.05, use_vlines=True, adjusted=False, fft=False, missing='none', zero=True, auto_ylims=False, bartlett_confint=False, vlines_kwargs=None, **kwargs)[source]¶
Plot auto/cross-correlation grid
Plots lags on the horizontal axis and the correlations on the vertical axis of each graph.
- Parameters:
x (array_like) – 2D array of time-series values: rows are observations, columns are variables.
varnames (sequence of str, optional) – Variable names to use in plot titles. If
xis a pandas dataframe andvarnamesis provided, it overrides the column names of the dataframe. Ifvarnamesis not provided andxis not a dataframe, variable namesx[0],x[1], etc. are generated.fig (Matplotlib figure instance, optional) – If given, this figure is used to plot in, otherwise a new figure is created.
lags ({int, array_like}, optional) – An int or array of lag values, used on horizontal axes. Uses
np.arange(lags)when lags is an int. If not provided,lags=np.arange(len(corr))is used.negative_lags (bool, optional) – If True, negative lags are shown on the horizontal axes of plots below the main diagonal.
alpha (scalar, optional) – If a number is given, the confidence intervals for the given level are plotted, e.g. if alpha=.05, 95 % confidence intervals are shown. If None, confidence intervals are not shown on the plot.
use_vlines (bool, optional) – If True, shows vertical lines and markers for the correlation values. If False, only shows markers. The default marker is ‘o’; it can be overridden with a
markerkwarg.adjusted (bool) – If True, then denominators for correlations are n-k, otherwise n.
fft (bool, optional) – If True, computes the ACF via FFT.
missing (str, optional) – A string in [‘none’, ‘raise’, ‘conservative’, ‘drop’] specifying how NaNs are to be treated.
zero (bool, optional) – Flag indicating whether to include the 0-lag autocorrelations (which are always equal to 1). Default is True.
auto_ylims (bool, optional) – If True, adjusts automatically the vertical axis limits to correlation values.
bartlett_confint (bool, default False) – If True, use Bartlett’s formula to calculate confidence intervals in auto-correlation plots. See the description of
plot_acffor details. This argument does not affect cross-correlation plots.vlines_kwargs (dict, optional) – Optional dictionary of keyword arguments that are passed to vlines.
**kwargs (kwargs, optional) – Optional keyword arguments that are directly passed on to the Matplotlib
plotandaxhlinefunctions.
- Returns:
If fig is None, the created figure. Otherwise, fig is returned. Plots on the grid show the cross-correlation of the row variable with the lags of the column variable.
- Return type:
Figure
See also
statsmodels.graphics.tsaplotsExamples
>>> import pandas as pd >>> import matplotlib.pyplot as plt >>> import statsmodels.api as sm
>>> dta = sm.datasets.macrodata.load_pandas().data >>> diffed = dta.diff().dropna() >>> sm.graphics.tsa.plot_accf_grid(diffed[["unemp", "infl"]]) >>> plt.show()