Histogram vs Bar Chart

โฑ๏ธ 35 sec read ๐Ÿ“Š Visualization

A histogram shows the distribution of one continuous variable by grouping values into bins; a bar chart compares values across discrete categories. They look similar but answer different questions, and mixing them up misleads readers.

What Is the Difference Between a Histogram and a Bar Chart?

A histogram's x-axis is a continuous number line (age, price, response time) sliced into bins, so bar order and width carry meaning. A bar chart's x-axis is a set of labels (region, product, month name) that you can reorder freely, often by value.

import matplotlib.pyplot as plt

# Histogram: distribution of a continuous variable
plt.hist(order_values, bins=20)

# Bar chart: comparison across categories
plt.bar(["North", "South", "East", "West"], region_sales)

Why Do Histogram Bars Have No Gaps?

Adjacent histogram bars touch because each bin ends exactly where the next begins โ€” the gap-free bars signal a continuous axis. Bar charts use gaps to signal that each bar is a separate, unordered category. If you add gaps to a histogram, readers will misread the bins as categories.

# matplotlib's hist() has no gaps by default. If you build one
# manually with bar(), set width to the full bin size:
plt.bar(bin_edges[:-1], counts, width=bin_width, align="edge")

How Do You Choose Histogram Bin Width?

There is no single right bin width โ€” too few bins hide the shape, too many turn it into noise. Start with an automatic rule, then adjust until the shape is stable.

import numpy as np

# Let numpy pick using the Freedman-Diaconis / Sturges hybrid
plt.hist(data, bins="auto")

# Or compute Freedman-Diaconis yourself:
q75, q25 = np.percentile(data, [75, 25])
bin_width = 2 * (q75 - q25) / len(data) ** (1/3)

Always try two or three widths. A bimodal distribution can look unimodal with wide bins, and that changes the conclusion.

Common Pitfalls

Pro Tip: Ask "could I reorder the x-axis without losing meaning?" If yes, it's categorical โ€” use a bar chart. If no, it's continuous โ€” use a histogram.

โ† Back to Visualization Tips