liveBook · Manning

Histogram

As explained in Grokking Statistics

A histogram is a chart that divides numerical data into equal-width intervals and displays the count in each interval.

A histogram is a bar chart that divides numerical data into equal-width intervals, or bins, and counts the values in each one. It reveals which ranges are common and shows the overall shape of the data. section 2.20

Tornado widths

Plotting tornado-path widths with 60 bins reveals heavy right skew: most tornadoes are relatively narrow, while a long tail contains wider outliers. Increasing the bin count adds detail; using too few bins oversmooths the shape, while using too many can make it noisy. Compare the histogram with the mean, median, and percentiles before interpreting it. section 2.20

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

df = pd.read_csv("https://raw.githubusercontent.com/thomasnield/"
              "training-data-repository/refs/heads/main/TORNADO_TRX.csv")


tor_width = df['TOR_WIDTH']

print("MEAN: ", np.mean(tor_width))          # MEAN:  215.18971962616823
print("MEDIAN: ", np.median(tor_width))      # MEDIAN:  100.0
print("ST DEV: ", np.std(tor_width, ddof=1)) # ST DEV:  315.83093225491433

print("25th PCT: ", np.percentile(tor_width, 25)) # 25th PCT:  50.0
print("75th PCT: ", np.percentile(tor_width, 75)) # 75th PCT:  250.0

print(df['TOR_F_SCALE'].value_counts())
# TOR_F_SCALE
# EF1    1250
# EF0    1047
# EFU     497
# EF2     323
# EF3      86
# EF4       7

# Create a histogram using matplotlib
plt.hist(tor_width, bins=60, edgecolor='black')  # Adjust bins as needed
plt.title('Histogram of Tornado Width')
plt.xlabel('Width')
plt.ylabel('Frequency')
plt.grid(True, alpha=0.3)
plt.show()

Run the Python example to calculate summary statistics and create a Matplotlib histogram of tornado widths. section 2.20

How Grokking Statistics covers it

How deep it goes
Defines bins and interprets skew, outliers, and bin-count tradeoffs, but stops short of formal derivations.
Examples
Uses tornado-path widths, 60 bins, and comparisons between mean, median, percentiles, and the visible distribution.
What you can do after
Apply it via Matplotlib to visualize numerical distributions and investigate skew, common ranges, and outliers.
How it connects
Connects histograms with mean, median, percentiles, standard deviation, skew, outliers, and interquartile range.

Also explained in

Compare how 11 books explain histogram →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Statistics. The section links point to the parts of the book it draws on.