Skip to content
svgestimation-plot

Estimation plot (Gardner–Altman)

How big is the difference between two groups, and how precisely is it estimated?

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

How to read it

  1. Read the left of the chart: every observation by group, with the group means.
  2. Read the floating axis at the right: the difference between groups.
  3. Read its interval: how large the difference could plausibly be.
  1. Callout 1: The observations and mean of the first group.
  2. Callout 2: The mean difference with its interval.
  3. Callout 3: The floating axis, anchored at the first group's mean.

Watch out

  • If the interval crosses zero, the data are compatible with no difference, but also with others in the interval.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Points are jittered deterministically by row; group lines are the means; the right axis is the left axis shifted so 0 sits at the first group's mean.
  • The difference and its interval come from the engine (Welch t, bootstrap or another estimator); without them the plain mean difference is shown with no interval.
  • Estimation first: read the size and the interval, not only whether it excludes 0.
# Estimation plot (Gardner–Altman) — Codesplash Chart Lab (recipe "estimation-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("estimation-plot-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["supplement"] = pd.Categorical(df["supplement"].astype("string"), categories=["VC", "OJ"])

_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)))
def first(col):
    """The first finite value of a column the engine repeats on every row (None if absent)."""
    if col is None:
        return None
    v = pd.to_numeric(df[col], errors="coerce").dropna()
    return float(v.iloc[0]) if len(v) else None
V = "length"
G = "supplement"
E = "difference"
EL = "diff low"
EH = "diff high"
d = df.dropna(subset=[V, G])
g1, g2 = levels_of(d[G])[:2]
a, b = d.loc[d[G].astype(str) == str(g1), V], d.loc[d[G].astype(str) == str(g2), V]
m1, m2 = a.mean(), b.mean()
eff = first(E) if first(E) is not None else m2 - m1
lo, hi = first(EL), first(EH)
rng = np.random.default_rng(1)
fig, (ax, axd) = plt.subplots(1, 2, figsize=(8, 4.5), sharey=True, gridspec_kw={"width_ratios": [2, 1]})
for i, (s, m) in enumerate([(a, m1), (b, m2)]):
    ax.scatter(i + rng.uniform(-0.15, 0.15, len(s)), s, s=14, alpha=0.6, color=PALETTE[i])
    ax.hlines(m, i - 0.3, i + 0.3, color=plt.rcParams["text.color"], linewidth=2)
ax.set_xticks([0, 1], [str(g1), str(g2)])
ax.set_ylabel(V)
# Floating difference axis: 0 sits at the first group's mean (Gardner & Altman 1986).
axd.axhline(m1, color=REF, linestyle=":", linewidth=1)
axd.errorbar(0, m1 + eff, yerr=[[eff - lo], [hi - eff]] if lo is not None and hi is not None else None, fmt="o", color=PALETTE[1], capsize=4, markersize=8)
axd.set_xticks([0], [f"{g2} − {g1}"])
axd.set_xlim(-0.6, 0.6)
sec = axd.secondary_yaxis("right", functions=(lambda v: v - m1, lambda v: v + m1))
sec.set_ylabel("difference")
plt.show()

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