statsmodels.graphics.tsaplots.plot_ccf¶
-
statsmodels.graphics.tsaplots.plot_ccf(x, y, *, ax=
None, lags=None, negative_lags=False, alpha=0.05, use_vlines=True, adjusted=False, fft=False, title='Cross-correlation', auto_ylims=False, vlines_kwargs=None, **kwargs)[source]¶ Plot the cross-correlation function
Correlations between
xand the lags ofyare calculated.The lags are shown on the horizontal axis and the correlations on the vertical axis.
- Parameters:¶
- x : array_like¶
Arrays of time-series values.
- y : array_like¶
Arrays of time-series values.
- ax : AxesSubplot, optional¶
If given, this subplot is used to plot in, otherwise a new figure with one subplot is created.
- lags : {int, array_like}, optional¶
An int or array of lag values, used on the horizontal axis. 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 axis.
- 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 cross-correlations are n-k, otherwise n.
- fft : bool, optional¶
If True, computes the CCF via FFT.
- title : str, optional¶
Title to place on plot. Default is ‘Cross-correlation’.
- auto_ylims : bool, optional¶
If True, adjusts automatically the vertical axis limits to CCF values.
- 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:¶
The figure where the plot is drawn. This is either an existing figure if the ax argument is provided, or a newly created figure if ax is None.
- Return type:¶
Figure
Examples
>>> 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_ccf(diffed["unemp"], diffed["infl"]) >>> plt.show()