Skip to content

Histogram

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.

diagram From raw values to a histogram mermaid
Values are split into evenly spaced bins, then a bar is drawn per bin showing how many values fall inside it.

Basic histogram

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()
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

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()
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):

sketch A histogram bins your data p5.js
Each value falls into a bin; the bar height is the count in that bin, revealing the distribution's shape.

Tip

Histograms are a first check before transformations (like log scaling).

Next

Continue to Scatter Plot to check the relationship between two numeric variables.

🧪 Try It Yourself

Exercise 1 – Set the bin count

Exercise 2 – Read the bin counts

Exercise 3 – Compare bin widths

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did