ACF and PACF

plot_acf.

plot_acf is a matplotlib figure — call plt.show(). Keep lags few.

Goal

Plot ACF of a short AR-like series.

import numpy as np
from statsmodels.graphics.tsaplots import plot_acf
rng = np.random.default_rng(0)
x = rng.normal(size=40)
plot_acf(x, lags=8)
plt.show()
print('ok')
import numpy as np
from statsmodels.tsa.stattools import acf
print(acf(np.array([1.0, 2, 1, 2, 1, 2]), nlags=3, fft=False).round(3))
import numpy as np
from statsmodels.graphics.tsaplots import plot_pacf
plot_pacf(np.random.default_rng(0).normal(size=50), lags=6, method='ywm')
plt.show()
print('ok')
import numpy as np
print(np.corrcoef([1, 2, 3, 4][:-1], [1, 2, 3, 4][1:]))