Skip to content
svgacf-plot

ACF / PACF (precomputed)

Is a series (or a model's residuals) autocorrelated, and at which lags?

Demo data · seed 20261101 · 48 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read bars outside the band as autocorrelation beyond noise.
  2. For model residuals, you want nothing outside.
  3. A spike at the seasonal lag means the season is not fully modelled.
  1. Callout 1: A bar beyond the band, at the seasonal lag.
  2. Callout 2: The band: the range for white noise.
  3. Callout 3: The same lag on the partial side.

Watch out

  • About 1 lag in 20 pokes out by chance.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the run's numbers as given (computed by the host's cs-ml evaluation or the Python/R engine); the chart computes nothing statistical.
  • Correlations come from the engine (statsmodels acf/pacf ↔ R acf/pacf on the residuals or the series); the band is the engine's ±1.96/√n white-noise bound when sent.
  • Use the time-series family's "acf" recipe to compute these from raw data instead.
# ACF / PACF (precomputed) — Codesplash Chart Lab (recipe "acf-plot")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("acf-plot-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["kind"] = pd.Categorical(df["kind"].astype("string"), categories=["acf", "pacf"])

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
def levels_of(s):
    """Declared level order (categoricals), else order of first appearance."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [v for v in s.cat.categories if (s == v).any()]
    return list(dict.fromkeys(s.dropna().astype(str)))
LAG = "lag (months)"
ACF = "correlation"
B = "bound"
KIND = "kind"
d = df.dropna(subset=[LAG, ACF]).sort_values(LAG)
kinds = levels_of(d[KIND]) if KIND else [None]
fig, axes = plt.subplots(1, len(kinds), figsize=(4.2 * len(kinds) + 1, 3.8), squeeze=False, sharey=True)
for ax, k in zip(axes[0], kinds):  # ACF and PACF side by side
    g = d if k is None else d[d[KIND].astype(str) == str(k)]
    bound = float(g[B].iloc[0]) if B else None
    if bound is not None:
        ax.axhspan(-bound, bound, color=GREY, alpha=0.4, lw=0)  # ±1.96/√n
    out = (g[ACF].abs() > bound) if bound is not None else pd.Series(False, index=g.index)
    cols = np.where(out, "#ce5342", PALETTE[0])
    ax.vlines(g[LAG], 0, g[ACF], colors=cols, linewidth=2)
    ax.scatter(g[LAG], g[ACF], c=cols, s=14, zorder=3)
    ax.axhline(0, color="grey", linewidth=0.8)
    ax.set_title(str(k).upper() if k is not None else ACF, fontsize=10)
    ax.set_xlabel(LAG)
axes[0, 0].set_ylabel(ACF)
fig.tight_layout()
plt.show()

Needs pandas, numpy, matplotlib · reads acf-plot-demo.csv · app theme from the optional codesplash helper