Histograms

A histogram shows how values are distributed.

It groups numerical values into bins and counts how many values fall in each bin.

plt.hist(values, bins=5)

Use a histogram when you want to inspect:

  • range;
  • concentration;
  • skew;
  • outliers;
  • whether values are roughly centered.

Plot a small distribution

Inspect a distribution

Runs locally with Python in your browser.

Ready to run.

The value 8 is far from most of the others. A histogram makes that easier to notice.

Bins affect the view

The same data can look different with different bin counts. Too few bins hide structure. Too many bins can make small data look noisy.

For learning examples, choose a small number of bins and explain what you are trying to inspect.

Histograms are not sequence plots

A histogram ignores order. If order matters, use a line plot. If distribution matters, use a histogram.

Exercise: Distribution plot

Which plot type is used to inspect the distribution of one numerical array?

Answer it first, then check.

Hint

Look for the plot that divides the value range into bins and counts values in each bin.

Solution

Use a histogram. It summarizes the distribution of one numerical array by counting values within ranges.