Skip to content
svgbrushablepp

Normal P–P plot

Does the centre of a distribution match a normal shape?

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

How to read it

  1. Points on the diagonal: the fitted normal's probabilities match the data's.
  2. An S shape around the diagonal means the data's centre differs from a normal's.
  3. Use the band to judge whether a departure is more than noise.
  1. Callout 1: Diagonal: where the data and the fitted normal agree.
  2. Callout 2: Sagging below the diagonal in the middle: a shape mismatch near the centre.
  3. Callout 3: Band: the range noise alone would allow.

Watch out

  • It is least sensitive in the tails. Use a Q–Q plot when the tails matter.

Defaults

95% Kolmogorov band
On
Shade the range a correct normal fit would stay inside 95% of the time.

Pinned in the code

  • x: plotting positions R `ppoints(n)`; y: Φ((x₍ᵢ₎ − x̄)/s) with s using n − 1.
  • Band: ±ε around y = x with the DKW constant ε = √(ln(2/0.05)/(2n)); with estimated mean and SD it is conservative (Lilliefors) — a visual guide, not a test.
# Normal P–P plot — Codesplash Chart Lab (recipe "pp")
# controls: band=true
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("pp-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

def ppoints(n):
    """R ppoints(n): (i − a)/(n + 1 − 2a) with a = 3/8 for n ≤ 10, else 1/2."""
    a = 3 / 8 if n <= 10 else 0.5
    return (np.arange(1, n + 1) - a) / (n + 1 - 2 * a)

x = np.sort(df["repair_h"].dropna().to_numpy(dtype=float))
n = x.size
p = ppoints(n)  # theoretical: R plotting positions
F = stats.norm.cdf((x - x.mean()) / x.std(ddof=1))  # empirical: Φ((x − x̄)/s), s with n − 1

fig, ax = plt.subplots(figsize=(5.5, 5))
eps = np.sqrt(np.log(2 / 0.05) / (2 * n))  # DKW constant: a visual guide (conservative with estimated mean/SD)
t = np.linspace(0, 1, 101)
ax.fill_between(t, np.clip(t - eps, 0, 1), np.clip(t + eps, 0, 1), color=PALETTE[0], alpha=0.15, linewidth=0, label="95% Kolmogorov band")
ax.plot([0, 1], [0, 1], color=plt.rcParams["text.color"], linewidth=1)
ax.scatter(p, F, s=12, color=PALETTE[0], linewidths=0)
ax.set_xlabel("Theoretical cumulative probability")
ax.set_ylabel("Empirical: Φ((repair_h − mean) / sd)")
ax.legend()
plt.show()

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

  • DuckDB has no normal CDF function, so there is no geometry SQL for P–P plots.