Explore autocorrelation with a lag plot

Visualize

Explore autocorrelation with a lag plot

Created: Last updated: Read time: 1 min

To detect autocorrelation in a time series, plot the previous value versus the current value. An upward slope means strong autocorrelation and a readable pattern.

import numpy as np
import matplotlib.pyplot as plt

rng = np.random.default_rng(11)
series = np.cumsum(rng.normal(0, 1.2, size=120)) + 50
lag = 1

x_prev = series[:-lag]
x_curr = series[lag:]

fig, ax = plt.subplots(figsize=(4.4, 4.4))
ax.scatter(x_prev, x_curr, color="#38bdf8", alpha=0.7)

coef = np.corrcoef(x_prev, x_curr)[0, 1]
ax.set_xlabel("Value at t-1")
ax.set_ylabel("Current value")
ax.set_title(f"Lag {lag} scatter (corr {coef:.2f})")
ax.grid(alpha=0.2)

lims = [min(series) - 2, max(series) + 2]
ax.plot(lims, lims, color="#475569", linestyle="--", linewidth=1)
ax.set_xlim(lims)
ax.set_ylim(lims)

fig.tight_layout()

plt.show()

An upward slope indicates strong autocorrelation.

Reading tips #

  • Points aligned in an upward line suggest strong autocorrelation and persistent trends.
  • A circular cloud implies weak autocorrelation, close to a random walk.
  • Small multiples across lags help decide which lag features to use.