Skip to content
svgpvalue-qq

p-value Q–Q plot

Are there more small p-values than chance alone would give?

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

How to read it

  1. Read x as the expected p-value on a log scale, y as the observed one.
  2. On the diagonal: as expected under the null.
  3. Above the band: more small p-values than chance would give.
  1. Callout 1: These tests stand out above the band.
  2. Callout 2: Most p-values are on the diagonal.
  3. Callout 3: The band under the null.

Watch out

  • Correlated tests can look inflated; check for shared samples.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the p-values as given; the band is the Beta(i, k + 1 − i) 2.5% and 97.5% quantiles of the i-th smallest of k null uniforms (pointwise, not simultaneous).
  • Points above the band are coloured: more small p-values than the null predicts.
# p-value Q–Q plot — Codesplash Chart Lab (recipe "pvalue-qq")
# 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("pvalue-qq-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")
P = "p"
p = pd.to_numeric(df[P], errors="coerce").dropna()
p = np.sort(p[(p > 0) & (p <= 1)].to_numpy())
k = len(p)
i = np.arange(1, k + 1)
expected = -np.log10(i / (k + 1))
observed = -np.log10(p)
band_low = -np.log10(stats.beta.ppf(0.975, i, k + 1 - i))  # order statistics of uniform p-values
band_high = -np.log10(stats.beta.ppf(0.025, i, k + 1 - i))
hi = max(1, expected.max(), observed.max(), band_high.max()) * 1.06
fig, ax = plt.subplots(figsize=(6, 6))
ax.fill_between(expected, band_low, band_high, color=GREY, alpha=0.5, lw=0, label="95% band under the null")
ax.plot([0, hi], [0, hi], color=REF, linestyle="--", linewidth=1)
ax.plot(expected, observed, "o", color=PALETTE[0], markersize=4)
ax.set_xlim(0, hi)
ax.set_ylim(0, hi)
ax.set_xlabel("Expected −log10 p")
ax.set_ylabel("Observed −log10 p")
ax.legend(fontsize=8, loc="upper left")
plt.show()

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