Skip to content
svgbrushableecdf

ECDF

What share of values falls below any threshold, and how do groups differ across the whole range?

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

How to read it

  1. Pick a value on the x axis and read up: the curve's height is the share of rows at or below that value.
  2. Read across at 50% to find each group's median, at 90% for the upper tail.
  3. Where one curve sits to the right of another across the whole range, that group has larger values throughout.
  1. Callout 1: Read across at 50%: each group's median.
  2. Callout 2: The curve further right has larger values at that share.
  3. Callout 3: The band: uncertainty around each curve.

Watch out

  • Steep is not high: a steep section means many values packed into a narrow range.
  • Crossing curves mean no group is larger throughout; say where each one leads.

Defaults

DKW 95% band
On
Shade a band that holds the whole true curve 95% of the time.
Median reference
On
Draw a reference at 50%, so you can read medians off the curve.
Show 1 − F (exceedance)
Off
Plot the share above each value rather than below it.

Pinned in the code

  • F̂(x) = #{xᵢ ≤ x}/n, right-continuous steps (R `ecdf`, `scipy.stats.ecdf`).
  • Band: Dvoretzky–Kiefer–Wolfowitz, F̂ ± ε with ε = √(ln(2/α)/(2n)), α = 0.05, clipped to [0, 1] — simultaneous over x.
  • Median marker at the type-7 median.
# ECDF — Codesplash Chart Lab (recipe "ecdf")
# controls: band=true, median=true, complement=false
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"]
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
SERIES_DASHES = ["-", (0, (6, 3)), (0, (1.5, 2.5)), (0, (8, 3, 2, 3)), (0, (12, 4)), (0, (3, 3)), (0, (8, 2, 2, 2, 2, 2)), (0, (1.5, 5))]
SERIES_MARKERS = ["o", "s", "^", "D", "P", "*", "2", "v"]

df = pd.read_csv("ecdf-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["device"] = pd.Categorical(df["device"].astype("string"), categories=["Desktop", "Mobile", "Tablet"])

def groups(frame, value, group=None, max_levels=12):
    """(label, values) per group in level order; rows missing the value or the group are dropped."""
    if group is None:
        return [(value, frame[value].dropna().to_numpy(dtype=float))]
    d = frame[[value, group]].dropna()
    out = []
    for level in list(d[group].cat.categories)[:max_levels]:
        v = d.loc[d[group] == level, value].to_numpy(dtype=float)
        if v.size:
            out.append((str(level), v))
    return out

parts = groups(df, "minutes", "device", max_levels=8)
fig, ax = plt.subplots(figsize=(7, 4))
for i, (label, v) in enumerate(parts):
    color = PALETTE[i % len(PALETTE)]
    many = len(parts) > 1  # several groups: a dash and a median marker shape per group, as in the app
    ax.ecdf(v, complementary=False, color=color, linewidth=1.8, linestyle=SERIES_DASHES[i % 8] if many else "-", label=label)  # F̂(x) = #{xᵢ ≤ x}/n, right-continuous
    xs = np.unique(v)
    F = np.searchsorted(np.sort(v), xs, side="right") / v.size
    eps = np.sqrt(np.log(2 / 0.05) / (2 * v.size))  # DKW 95% band, simultaneous over x
    lo, hi = np.clip(F - eps, 0, 1), np.clip(F + eps, 0, 1)
    ax.fill_between(xs, lo, hi, step="post", color=color, alpha=0.15, linewidth=0)
    ax.axvline(np.median(v), color=color, linestyle=":", linewidth=1)  # type-7 median
    ax.plot([np.median(v)], [0.5], linestyle="none", marker=SERIES_MARKERS[i % 8] if many else "o", markersize=6, markerfacecolor=plt.rcParams["axes.facecolor"], markeredgecolor=color, markeredgewidth=1.5)
ax.set_xlabel("minutes")
ax.set_ylabel("F(x)")
if len(parts) > 1:
    ax.legend()
plt.show()

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