Construct a cumulative distribution from observed values, preserving ties and sample size.
Empirical CDFs: read thresholds and tails without choosing bins
The step answers a threshold question
An empirical cumulative distribution function, or ECDF, gives the fraction of observed values less than or equal to each threshold. A point at 47 minutes and 0.8 means 80 percent of observations took at most 47 minutes. Unlike a histogram, it needs no bin width, so comparisons across groups are less sensitive to display choices. It still depends on the population, missing-value policy and observation window. Distribution plots should expose those rules before any percentile is interpreted.
Ties produce one jump
Repeated measurements at the same value create one larger step. If 31 of 81 jobs finish at exactly 12 minutes, the ECDF rises by 31/81 there; do not create a fake continuous slope between identical values. To compute a nearest-rank percentile, choose the first observed value whose cumulative share meets or exceeds the requested probability. Other quantile conventions interpolate and can return a number no job achieved. State the convention, especially for service targets. Sampling rules determine whether a percentile describes all jobs or a selected frame.
Keep the tail visible
Most observations can cluster near a short duration while a few long delays drive customer pain. An ECDF makes the proportion under a service threshold easy to read, but the far-right tail may still be squeezed by the axis. Add an inset, tail table or direct threshold counts when the rare cases matter. A survival-style complementary curve, one minus the ECDF, answers what fraction exceeds a threshold; be clear about strict versus inclusive inequalities at ties. Small samples need counts beside smooth-looking curves.
Compare only compatible cohorts
Two curves can differ because of case mix, eligibility, time window or measurement precision. Use consistent axis limits and units, label sample sizes, and show whether pending cases were excluded or censored. A naive ECDF of only completed jobs makes the slow unfinished work disappear. For a queue with unresolved jobs, use an analysis that handles censoring or restrict the claim to completed jobs. Observation status is part of the underlying data, not a cosmetic legend choice.
Worked contract
from math import ceil, isfinite
def completion_ecdf(minutes: list[float]) -> list[tuple[float, int, float]]:
if not minutes or any(not isfinite(value) or value < 0 for value in minutes):
raise ValueError("need finite nonnegative durations")
ordered = sorted(minutes)
steps = []
for value in ordered:
if steps and steps[-1][0] == value:
steps[-1] = (value, steps[-1][1] + 1, 0.0)
else:
steps.append((value, 1, 0.0))
cumulative = 0
result = []
for value, tied, _ in steps:
cumulative += tied
result.append((value, tied, cumulative / len(ordered)))
return result
durations = [12, 12, 31, 47, 81]
curve = completion_ecdf(durations)
nearest_rank_80 = sorted(durations)[ceil(0.8 * len(durations)) - 1]
assert curve[0] == (12, 2, 0.4)
assert curve[-1][2] == 1.0 and nearest_rank_80 == 47Performance and operating cost
Sorting N durations costs O(N log N) time and O(N) space for the ordered copy and output; scanning ties is O(N). Already-sorted warehouse output avoids the local sort. A chart with many distinct observations may still need visual reduction at screen resolution, but threshold queries should use the exact ordered values. The simple ECDF treats every supplied duration as complete and equally weighted; it is not a censored-data estimator.
Common Mistakes
- Reading a completed-only ECDF as the distribution of all started jobs.
- Treating a large jump at a tied value as a renderer defect.
- Quoting a percentile without its sample size and quantile convention.
- Moving axis bounds between cohorts and comparing apparent steepness.
Validation drill
Build curves for two depot cohorts of 47 and 81 completed cases. Include repeated durations and unresolved work, then report the fraction within 31 minutes and exactly which cases were excluded.
Read next
- Distribution plots: keep the tail, missing values and bin policy visible
- Uncertainty on charts: show denominators and intervals beside estimates
- Large chart series: reduce marks without erasing spikes
- Time-series charts: distinguish missing days, zeros and provisional periods
Continue this visualization path
- Box and violin charts: compare groups without inventing density
- Q–Q plots: compare distribution shape beyond one summary number
- Ridgeline plots: compare distributions without hiding their size
- Survival curves: show who remains at risk after each event
- Lorenz curves: audit ranked shares before quoting a Gini value
- P–P plots: compare observed probabilities with a fixed reference CDF
