Skip to content
Tutorials Center
My learning

Topics

Lesson 8 of 38 ยท Distributions

Distributions: Visualizing One Variable

Learn what a distribution is and how seaborn's displot draws histograms, KDE curves and ECDFs. Read shape, center, spread, skew and outliers from a plot.

Before comparing groups or fitting models, look at each variable on its own. A distribution answers: which values occur, and how often? Is the variable symmetric or skewed, concentrated or spread out, single-peaked or split into clusters? Seaborn's distribution functions make these questions one line each, and displot is the figure-level entry point that wraps all of them.

What to look for

Reading a distribution

Center Where is a typical value?
Spread How wide is the range?
Peaks One mode, or several groups?
Skew and outliers Is one tail long? Any extremes?

Every plot in this chapter helps answer these four questions.

1 / 2

displot: the figure-level entry point

sns.displot(data=df, x="col", kind="hist") chooses the plot with kind:

kind Axes-level function Shows
"hist" (default) histplot Counts or densities in bins
"kde" kdeplot A smoothed density estimate
"ecdf" ecdfplot Cumulative proportion, no tuning needed

Because displot is figure-level, it supports col= and row= to split by category, plus hue= for overlays. We will use a simulated table of penguin measurements (three species with different average body sizes) throughout this chapter. The numbers are generated with a fixed seed so they are the same every time.

Python The three kinds of displot

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.

All three describe the same data. The mass variable has two bumps because Gentoo penguins are heavier than the other two species: a mixture that a single summary number (the mean) would hide.

Overlaying and splitting groups

Add hue to draw one distribution per category in the same axes, or col to give each its own panel:

Python hue overlays and col facets

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.

Overlays make comparison direct but get messy with more than three or four groups. Facets (col=) keep each distribution readable and share the axes, so panels are comparable.

Choosing between the three

  • Histogram: the safest default. You see actual counts. The appearance depends on the bin width, so check one or two settings.
  • KDE: nice for comparing smooth shapes and for spotting multiple peaks. It can show density where there is no data (below zero, for example) and its width depends on a bandwidth.
  • ECDF: no bins or bandwidth, so nothing to tune. It shows percentiles directly and makes group differences easy to read when curves are shifted. It is less intuitive for beginners.

A habit worth keeping: draw a histogram and a KDE for the same variable before you decide what it looks like.

Skew and outliers

Right-skewed variables (incomes, prices, waiting times) have a long tail on the right; the mean is pulled above the median. Try a log scale (log_scale=True) to see structure that is squashed against zero. Outliers appear as isolated bars or a thin tail. They deserve a look, not automatic removal: they might be errors, or the most interesting rows.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which displot kind has no bin width or bandwidth to tune?

    The empirical CDF is computed directly from the sorted data.
  2. 2. Body mass in a simulated penguin table has two bumps. What is the most likely explanation?

    Multiple peaks often mean a hidden grouping variable. Splitting by hue or col confirms it.
  3. 3. What does col='species' do in displot?

    col= facets the data into one subplot per category.
  4. 4. Why is displot a poor choice for placing a histogram into an existing subplot grid?

    Figure-level functions ignore ax=. The axes-level histplot, kdeplot and ecdfplot accept it.

Summary

  • A distribution tells you which values occur and how often: center, spread, peaks, skew and outliers.
  • displot(kind="hist" | "kde" | "ecdf") is the figure-level entry point; histplot, kdeplot and ecdfplot are the axes-level versions.
  • hue= overlays groups; col= and row= split them into panels.
  • Multiple peaks usually mean mixed groups.
  • Look at more than one representation before drawing conclusions.

Next: Histograms with histplot