Skip to content
svginterval-plot

Prediction intervals

Which observations fall outside their prediction intervals, and how wide are the intervals?

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

How to read it

  1. Read each bar as a row's prediction interval.
  2. Dots are the actual values.
  3. Red dots fall outside: are they at some part of the range or evenly scattered?
  1. Callout 1: One row's interval.
  2. Callout 2: A value outside its interval.
  3. Callout 3: The share covered.

Watch out

  • Width matters too: wide intervals are easy to keep correct but tell you little.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the run's numbers as given (computed by the Python/R engine); the chart computes nothing statistical.
  • Observations are ordered by `index` as sent (often sorted by the prediction or by time). Coverage counts actuals within [lower, upper].
# Prediction intervals — Codesplash Chart Lab (recipe "interval-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("interval-plot-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

I = "sale (sorted by prediction)"
A = "price ($100k)"
P = "predicted"
LO = "lower"
HI = "upper"
d = df.dropna(subset=[I, LO, HI]).sort_values(I)
inside = (d[A] >= d[LO]) & (d[A] <= d[HI])
fig, ax = plt.subplots(figsize=(8, 4.5))
if len(d) > 400:
    ax.fill_between(d[I], d[LO], d[HI], color=PALETTE[0], alpha=0.25, lw=0)
else:
    ax.vlines(d[I], d[LO], d[HI], color=PALETTE[0], alpha=0.45, linewidth=3)
ax.plot(d[I], d[P], color=PALETTE[0], linewidth=1.2, label="prediction")
ax.scatter(d.loc[inside, I], d.loc[inside, A], color="black", s=8, label=f"actual inside ({inside.mean():.1%} covered)")
ax.scatter(d.loc[~inside, I], d.loc[~inside, A], color="#ce5342", s=14, label="actual outside")
ax.set_xlabel(I)
ax.set_ylabel(A)
ax.legend(fontsize=8)
plt.show()

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