A histogram is really a bar plot in disguise: McKinney describes it as "a discretized display of value frequency." Your values get split into evenly spaced bins, and the bar height for each bin is simply how many values landed inside it.
flowchart LR A["Raw numeric values"] --> B["Split into N equal-width bins"] B --> C["Count values per bin"] C --> D["Draw one bar per bin"] D --> E["Shape reveals skew, outliers, spread"]
Basic histogram
import matplotlib.pyplot as plt
values = [55, 60, 62, 63, 65, 67, 70, 72, 76, 80, 81, 85, 90, 92, 95]
plt.figure(figsize=(7, 4))
plt.hist(values, bins=8, edgecolor="black")
plt.title("Distribution")
plt.xlabel("Value")
plt.ylabel("Count")
plt.tight_layout()
plt.show()Try different bins
import matplotlib.pyplot as plt
fig, axes = plt.subplots(1, 2, figsize=(10, 4), sharey=True)
axes[0].hist(values, bins=4, edgecolor="black")
axes[0].set_title("bins=4")
axes[1].hist(values, bins=12, edgecolor="black")
axes[1].set_title("bins=12")
plt.tight_layout()
plt.show()Visualize it
A histogram sorts your values into bins and draws a bar for each — the bar's height is how many values landed in that bin. Together the bars reveal the shape of the distribution (here, a bell centred near the middle):
Tip
Histograms are a first check before transformations (like log scaling).
Check your understanding
What does the height of a histogram bar represent?
Values are split into evenly spaced bins and each bar's height is the count in its bin.
Show answer
A — How many values fall inside that bin — Values are split into evenly spaced bins and each bar's height is the count in its bin.
What does bins=8 do in plt.hist(values, bins=8, edgecolor="black")?
bins sets how many intervals to use, and edgecolor draws black edges so the bars are easy to tell apart.
Show answer
A — Splits the range into 8 bins, and edgecolor outlines each bar — bins sets how many intervals to use, and edgecolor draws black edges so the bars are easy to tell apart.
What does the lesson show when comparing bins=4 with bins=12?
Too few bins hide detail and too many bins look noisy, so try different values.
Show answer
A — The shape of the histogram changes with the number of bins — Too few bins hide detail and too many bins look noisy, so try different values.
A histogram is a first check before which kind of step?
Looking at the distribution tells you whether a transform may help.
Show answer
A — Transformations like log scaling — Looking at the distribution tells you whether a transform may help.
Next
Continue to Scatter Plot to check the relationship between two numeric variables.
🧪 Try It Yourself
Exercise 1 – Set the bin count
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 2 – Read the bin counts
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 3 – Compare bin widths
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.