Skip to content
svgpvalue-histogram

p-value histogram

Do the p-values pile up near zero, or spread flat as under the null?

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

How to read it

  1. Read bars as how many p-values fall in each bin.
  2. A flat histogram matches a global null.
  3. A spike near zero suggests real signals; other shapes suggest a problem with the tests.
  1. Callout 1: A spike near zero: more small p-values than chance.
  2. Callout 2: The dashed line: expected under the null.

Watch out

  • A bump near 1 or a U-shape hints at a miscalibrated test, or a bias, rather than signal.

Defaults

Bins
10
How many bins to divide the range into.
Range 2 to 50, step 1

Pinned in the code

  • Bins are left-closed [a, b) except the last, which includes 1; the first bin is highlighted.
  • Under the global null with valid p-values the bars are flat at k / bins (dashed line).
# p-value histogram — Codesplash Chart Lab (recipe "pvalue-histogram")
# controls: bins=10
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("pvalue-histogram-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"
BINS = 10
p = pd.to_numeric(df[P], errors="coerce").dropna()
p = p[(p >= 0) & (p <= 1)]
fig, ax = plt.subplots(figsize=(7, 4.5))
counts, edges, patches = ax.hist(p, bins=np.linspace(0, 1, BINS + 1), color=PALETTE[0], alpha=0.55, edgecolor="white")
patches[0].set_alpha(1.0)  # the first bin is where real effects pile up
ax.axhline(len(p) / BINS, color=REF, linestyle="--", linewidth=1, label="expected under the global null")
ax.set_xlabel("p")
ax.set_ylabel("tests")
ax.legend(fontsize=8)
plt.show()

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