Skip to content
svgbland-altman

Bland–Altman plot

Do two measurement methods agree, is there a bias, and does it change with the level measured?

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

How to read it

  1. Read the middle line as the average difference (bias).
  2. Read the outer lines as the limits within which most differences fall.
  3. Look for a slope or a funnel: the disagreement may change with the level.
  1. Callout 1: Bias: the mean difference.
  2. Callout 2: Upper limit of agreement.
  3. Callout 3: Lower limit of agreement.

Watch out

  • Small limits don't prove agreement: compare them with what is clinically or practically acceptable.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the engine's numbers as given (precomputed by the Python or R analysis); the chart computes nothing statistical.
  • Engine-supplied controls: bias, lower, upper (lines), biasLow/biasHigh, lowerLow/lowerHigh, upperLow/upperHigh (confidence bands), slope/intercept (proportional-bias regression).
  • Without engine lines the chart shows bias = mean difference and limits bias ± 1.96·SD (SD with n − 1), as in Bland & Altman (1986).
# Bland–Altman plot — Codesplash Chart Lab (recipe "bland-altman")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats

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("bland-altman-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

_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")
MEAN = "mean of methods (L/min)"
DIFF = "Wright − mini (L/min)"
d = df.dropna(subset=[MEAN, DIFF])
n, bias, sd = len(d), d[DIFF].mean(), d[DIFF].std(ddof=1)
loa = (bias - 1.96 * sd, bias + 1.96 * sd)  # 95% limits of agreement
t = stats.t.ppf(0.975, n - 1)
se_bias, se_loa = sd / np.sqrt(n), sd * np.sqrt(3 / n)  # Bland & Altman (1999) approximate SEs
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.axhspan(bias - t * se_bias, bias + t * se_bias, color=PALETTE[0], alpha=0.12, lw=0)
for lim in loa:
    ax.axhspan(lim - t * se_loa, lim + t * se_loa, color=GREY, alpha=0.35, lw=0)
    ax.axhline(lim, color=REF, linestyle="--", linewidth=1)
ax.axhline(bias, color=PALETTE[0], linewidth=1.5)
ax.axhline(0, color="grey", linewidth=0.6)
ax.scatter(d[MEAN], d[DIFF], s=22, color=PALETTE[0], alpha=0.8)
for v, txt in [(bias, f"bias {bias:.3g}"), (loa[0], f"−1.96 SD {loa[0]:.3g}"), (loa[1], f"+1.96 SD {loa[1]:.3g}")]:
    ax.annotate(txt, (1, v), xycoords=("axes fraction", "data"), xytext=(-4, 3), textcoords="offset points", ha="right", fontsize=8)
ax.set_xlabel(MEAN)
ax.set_ylabel(DIFF)
plt.show()

Needs pandas, numpy, matplotlib, scipy · reads bland-altman-demo.csv · app theme from the optional codesplash helper