svgquantile-fan
Quantile fan
What range of futures does a probabilistic forecaster expect, step by step?
How to read it
- Read the dark line as the history and the coloured line as the median forecast.
- Read the widest band as the central 80% (10% to 90%), the narrower ones as smaller central shares.
- Watch how the bands widen with the horizon: that is how fast the model's uncertainty grows.
Watch out
- A pretrained model's bands are its own beliefs, not a calibrated guarantee: check their coverage in a backtest.
Defaults
No settings: the chart draws one way.
Pinned in the code
- Bands pair each quantile below the median with its mirror above (q and 1 − q), so the 10%–90% band covers the central 80% of the forecast distribution.
- Bands are drawn as overlapping translucent fills, so the darker centre is where several bands overlap; the median is the point forecast.
- The bands start at the last observed value so the hand-off from history to forecast is visible.
Use with care
Quantiles describe the model's uncertainty, not a guarantee: check how often actual values fell inside them in a backtest.
# Quantile fan — Codesplash Chart Lab (recipe "quantile-fan")
# 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("quantile-fan-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["month"] = pd.to_datetime(df["month"])
_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")
T = "month"
V = "passengers (thousands)"
Q = "quantile"
hist = df[df[Q].isna()].sort_values(T)
fc = df[df[Q].notna()].pivot_table(index=T, columns=Q, values=V, aggfunc="last").sort_index()
levels = sorted(fc.columns)
fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(hist[T], hist[V], color="black", linewidth=1.4, label="history")
for q in [l for l in levels if l < 0.5]: # central bands: q to 1 - q
mirror = min(levels, key=lambda l: abs(l - (1 - q)))
if abs(mirror - (1 - q)) < 1e-6:
ax.fill_between(fc.index, fc[q], fc[mirror], color=PALETTE[0], alpha=0.14 + 0.36 / max(1, len(levels) // 2), linewidth=0)
mid = min(levels, key=lambda l: abs(l - 0.5))
ax.plot(fc.index, fc[mid], color=PALETTE[0], linewidth=2, label="median (the forecast)")
ax.legend(fontsize=8)
plt.show()Needs pandas, numpy, matplotlib · reads quantile-fan-demo.csv · app theme from the optional codesplash helper
# Quantile fan — Codesplash Chart Lab (recipe "quantile-fan")
# controls: defaults
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
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 px.colors.qualitative.Plotly
df = pd.read_csv("quantile-fan-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["month"] = pd.to_datetime(df["month"])
_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")
T = "month"
V = "passengers (thousands)"
Q = "quantile"
hist = df[df[Q].isna()].sort_values(T)
fc = df[df[Q].notna()].pivot_table(index=T, columns=Q, values=V, aggfunc="last").sort_index()
levels = sorted(fc.columns)
x = list(fc.index)
fig = go.Figure(go.Scatter(x=hist[T], y=hist[V], mode="lines", line=dict(color="black"), name="history"))
for q in [l for l in levels if l < 0.5]:
mirror = min(levels, key=lambda l: abs(l - (1 - q)))
if abs(mirror - (1 - q)) < 1e-6:
fig.add_trace(go.Scatter(x=x + x[::-1], y=list(fc[mirror]) + list(fc[q])[::-1], fill="toself", fillcolor="rgba(70,110,200,0.18)", line=dict(width=0), name=f"{q:.0%}–{mirror:.0%}"))
mid = min(levels, key=lambda l: abs(l - 0.5))
fig.add_trace(go.Scatter(x=x, y=fc[mid], mode="lines", line=dict(color=PALETTE[0], width=2), name="median"))
fig.show()Needs pandas, numpy, plotly · reads quantile-fan-demo.csv · app theme from the optional codesplash helper
# Quantile fan — Codesplash Chart Lab (recipe "quantile-fan")
# controls: defaults
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
df <- read.csv("quantile-fan-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["month"]] <- as.POSIXct(df[["month"]], tz = "UTC")
tok <- if (has_cs) codesplashr::cs_palette(dark = FALSE) else list()
seq_ramp <- if (is.null(tok$sequential)) c("#eff6fd", "#1a469d") else tok$sequential # low → high
div_ramp <- if (is.null(tok$diverging)) c("#c13e2e", "#f3f5f8", "#0859ac") else tok$diverging # −, 0, +
ref_col <- if (is.null(tok$reference)) "#4e5661" else tok$reference
grey_col <- if (is.null(tok$dim)) "#ced1d6" else tok$dim
T <- "month"
V <- "passengers (thousands)"
Q <- "quantile"
hist <- df[is.na(df[[Q]]), , drop = FALSE]
fc <- df[!is.na(df[[Q]]), , drop = FALSE]
lv <- sort(unique(fc[[Q]]))
bands <- do.call(rbind, lapply(lv[lv < 0.5], function(q) {
m <- lv[which.min(abs(lv - (1 - q)))]
if (abs(m - (1 - q)) > 1e-6) return(NULL)
lo <- fc[fc[[Q]] == q, ]; hi <- fc[fc[[Q]] == m, ]
data.frame(t = lo[[T]], lo = lo[[V]], hi = hi[match(lo[[T]], hi[[T]]), V], band = sprintf("%g–%g%%", 100 * q, 100 * m))
}))
mid <- fc[fc[[Q]] == lv[which.min(abs(lv - 0.5))], ]
p <- ggplot() +
geom_ribbon(data = bands, aes(t, ymin = lo, ymax = hi, group = band), fill = cs_cat[1], alpha = 0.18) +
geom_line(data = hist, aes(.data[[T]], .data[[V]]), colour = "black", linewidth = 0.5) +
geom_line(data = mid, aes(.data[[T]], .data[[V]]), colour = cs_cat[1], linewidth = 0.8) +
labs(x = T, y = V)
print(p)Needs ggplot2 · reads quantile-fan-demo.csv · app theme from the optional codesplashr helper