Skip to content
svgforest

Forest plot

How large are several estimates, how precise, and which exclude the null?

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

How to read it

  1. Read each row as an estimate with its interval.
  2. Check the dashed reference line: an interval crossing it is compatible with no effect.
  3. Compare interval widths: wider means less precise.
  1. Callout 1: One estimate: the marker and its interval.
  2. Callout 2: Reference line: no effect.
  3. Callout 3: The estimate and its interval, as numbers.

Watch out

  • Crossing or not crossing the line isn't the same as large or small: read the size too.

Defaults

Reference (null) value
0
The value that means no effect, such as 0 for a difference or 1 for a ratio.
Range -1,000 to 1,000, step 0.1
Log scale (ratios)
Off
Use a log axis, the natural scale for ratios: 2 and ½ sit the same distance from 1.
Equivalence band ± (0 = none; ratio on log scale)
0
Shade the range of effects you would call practically zero.
Range 0 to 100, step 0.05

Pinned in the code

  • Draws the engine's numbers as given (precomputed by the Python or R analysis); the chart computes nothing statistical.
  • Rows keep the engine's order, top to bottom; the right margin repeats estimate [low, high].
  • Ratios (OR, RR, HR, IRR) use a log axis with the reference at 1, so equal ratios look equally far from the null.
  • Engine-supplied controls bandLow/bandHigh draw a smallest-effect-of-interest band (TOST / practical significance).
  • Marker area ∝ weight when given (meta-analysis style); otherwise all markers are equal.
# Forest plot — Codesplash Chart Lab (recipe "forest")
# controls: reference=0, log=false, bandHalf=0
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("forest-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["subgroup"] = pd.Categorical(df["subgroup"].astype("string"), categories=["All patients", "Age < 65", "Age ≥ 65", "Women", "Men", "Diabetes", "No diabetes"])

_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)))
LABEL = "subgroup"
EST = "mean difference (mmHg)"
LO = "lower"
HI = "upper"
G = None
W = "n"
REFV, LOG, HALF = 0, False, 0  # null value, log axis (ratios), equivalence band ±
d = df.dropna(subset=[LABEL, EST]).reset_index(drop=True)
y = np.arange(len(d))[::-1]  # first row at the top
groups = levels_of(d[G]) if G else [None]
fig, ax = plt.subplots(figsize=(8, 0.42 * len(d) + 1.4))
if HALF > 0:
    band = (REFV / max(HALF, 1 + 1e-9), REFV * max(HALF, 1 + 1e-9)) if LOG else (REFV - HALF, REFV + HALF)
    ax.axvspan(*band, color="#19966e", alpha=0.08, lw=0)
ax.axvline(REFV, color=REF, linestyle="--", linewidth=1)
wmax = d[W].max() if W else 1
for i, row in d.iterrows():
    col = PALETTE[groups.index(str(row[G])) % len(PALETTE)] if G else PALETTE[0]
    ax.plot([row[LO], row[HI]], [y[i], y[i]], color=col, linewidth=1.6)
    size = 24 + 110 * (row[W] / wmax) if W and wmax > 0 else 48  # marker area ∝ weight
    ax.scatter(row[EST], y[i], marker="s", s=size, color=col, zorder=3)
ax.set_yticks(y, d[LABEL].astype(str))
if LOG:
    ax.set_xscale("log")
ax.set_xlabel(EST)
if G:
    for j, g in enumerate(groups):
        ax.scatter([], [], marker="s", color=PALETTE[j % len(PALETTE)], label=g)
    ax.legend(fontsize=8)
plt.show()

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