Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 38 ยท Distributions

ECDF and Rug Plots

Use seaborn ecdfplot to read percentiles and compare groups without bins, and rugplot to mark every observation. Includes complementary ECDFs and combined plots.

Histograms and KDEs both depend on a setting: bin width or bandwidth. Two other tools need none. The empirical cumulative distribution function (ECDF) shows, for every value, the share of observations at or below it. A rug plot draws one small tick per observation along an axis, so you see the raw data behind a smooth curve. Together they are the most honest views of a single variable.

Reading an ECDF

An ECDF is a staircase that climbs from 0 to 1 (or 0 to 100%). To read it:

  • Find a value on the x axis and go up to the curve: the y height is the fraction of observations at or below that value.
  • Find a fraction on the y axis (0.5 is the median) and go across to the curve: the x position is that percentile.
  • Steep parts mean many observations are packed together; flat parts mean a gap.
Python ecdfplot with hue

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Where the dashed line at 0.5 meets each curve is that group's median, which matches the printed medians. The Pro curve lies to the right of Basic at every height: it is larger at every percentile, a strong, assumption-free statement that is hard to make from overlapping histograms.

Options for ecdfplot

  • stat="proportion" (default, 0 to 1), "percent" (0 to 100) or "count".
  • complementary=True flips the curve to "share above x", which is the survival function. It is ideal for questions like "what fraction of requests take longer than 2 seconds?".
  • log_scale=True helps heavy-tailed data. A complementary ECDF on log-log axes is the classic way to inspect a power-law tail.
  • weights="col" counts rows with weights, and hue, y= (a horizontal version) work as usual.
Python Complementary ECDF on a log scale

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The right plot answers "how often are requests slower than x?" directly. The vertical line sits where only 5% of requests are slower.

Rug plots

sns.rugplot adds a small tick at every observation along the x (or y) axis. On its own it shows density as how dense the ticks are; combined with a KDE or histogram it reveals gaps and outliers that smoothing hides. Options: height=0.05 sets the tick height as a fraction of the axes, alpha makes dense ticks darker, and expand_margins=False keeps the ticks from stretching the axis.

Python KDE with a rug underneath

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The rug shows that the two right-hand bumps are only two points, something the smooth curve alone downplays.

Shortcuts

  • kdeplot has no rug argument, but the figure-level displot(kind="kde", rug=True) adds the ticks in one call.
  • sns.histplot pairs well with sns.rugplot in the same axes.
  • For categorical comparisons of raw points, see strip and swarm plots.

Which plot answers which question?

Question Best view
What is the typical value, spread and skew? Histogram or KDE
What fraction is below a threshold? ECDF
What fraction exceeds a threshold (SLA)? Complementary ECDF
How do two groups differ at every percentile? ECDF with hue
Where exactly are the observations and outliers? Rug plot

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. On an ECDF, the curve at x = 40 has height 0.8. What does this mean?

    The ECDF height at x is the fraction of observations less than or equal to x.
  2. 2. Which argument turns an ECDF into 'share of values greater than x'?

    complementary=True plots 1 - ECDF, the survival function.
  3. 3. Why is an ECDF considered assumption-free for comparing groups?

    It is computed straight from the sorted data, so it has no tuning parameters.
  4. 4. What does a rug plot add to a density curve?

    The ticks show the raw data behind the smooth curve.

Summary

  • An ECDF shows the fraction of values at or below x; read percentiles straight off the curve.
  • ecdfplot supports hue, stat, complementary and log_scale; it has nothing to tune.
  • Compare groups by checking whether one ECDF lies to the right of another at all heights.
  • rugplot marks every observation and pairs well with KDEs and histograms.

Next: Two Variables: Bivariate Distributions