The histogram is on of the default ways to look at a dataset’s distribution. We essentially hand it a column of numbers and it shows where the values are concentrated, how widely they are spread out, and whether the distribution appears skewed. It’s simple, yet a familiar and useful data plot.
However, a histogram is not always a direct picture of the data. Before the chart appears on the screen, the values from our curve are divided into bins. The number of bins, their width and the position of their boundaries all affect the resulting shape of the histogram.
If we change any of those parameter, then the same dataset can appear smooth, bimodal or unexpectedly noisy.
This does not make the histogram a wrong choice, but it does mean that the histogram shows the data in a particular way, and how we view and set those parameters can influence the conclusions we draw.
Creating a Distribution With Two Modes
To see how this happens, we can create a synthetic porosity dataset representing two geological formations. Each formation contains 300 observations, with mean porosities of 0.15 and 0.20, and a standard deviation of 0.014.
import numpy as np
import matplotlib.pyplot as plt
rng = np.random.default_rng(3)
n = 600
pop_a = rng.normal(0.150, 0.014, n // 2)
pop_b = rng.normal(0.200, 0.014, n // 2)
por = np.clip(
np.concatenate([pop_a, pop_b]),
0.05,
0.30
)
plot_range = (0.05, 0.30)The two populations overlap, but they are sufficiently separated for the combined distribution itself to contain two modes.
Two geological groups do not always produce two peaks in a histogram. If their distributions overlap strongly enough, the combined data may be genuinely unimodal. In this example, we already know that two modes are present, so we can see how well the histogram reveals them.
The Bin Count Decides What You See
The number of bins controls the resolution of the histogram. With too few bins, the observations from different parts of the distribution are combined into the same broad intervals. This can make the real structure can disappear.
With too many bins, all of the small variations caused by random sampling can start to look like meaningful features. To illustrate this we can hold the data and plotting range constant whilst changing only the number of bins.
fig, axes = plt.subplots(
1,
4,
figsize=(16, 4),
sharey=True
)
for ax, bins in zip(axes, [6, 12, 18, 40]):
ax.hist(
por,
bins=bins,
range=plot_range
)
ax.set_xlim(plot_range)
ax.set_xlabel(”Porosity (fraction)”)
ax.set_title(f”{bins} bins”)
axes[0].set_ylabel(”Count”)
plt.tight_layout()
plt.show()This gives us the following figure:

With six bins, the centre of the distribution becomes a broad block. There is no clear valley separating the two populations, and it would be difficult to justify a claim that the data contains two modes.
At twelve bins, some structure begins to appear.
At eighteen bins, the two concentrations and the lower-density region between them are much clearer.
At forty bins, the broader pattern remains visible, but the bars also begin to jump up and down in response to relatively small differences in sample count. Some of those fluctuations could easily be mistaken for additional peaks.
Each histogram is a small summary of the same data, and can support different visual interpretations.
A low-resolution histogram can hide genuine structure, whilst a high-resolution histogram can give random sampling variation more visual importance than it deserves.
There Is No Universally Correct Number of Bins
It is tempting to select the 18 bin histogram as the correct one, but there is no single bin count that is best for every dataset and every question.
A histogram designed to show the broad range of a variable may need fewer bins than one intended to investigate subtle modes. Sample size, variability, skewness and outliers can all affect what works well.
This is why several rules have been developed for selecting bin widths automatically.
One commonly used option is the Freedman–Diaconis rule, which uses the interquartile range and sample size
fig, ax = plt.subplots(figsize=(6, 4.5))
ax.hist(
por,
bins=”fd”,
range=plot_range
)
ax.set_xlim(plot_range)
ax.set_xlabel(”Porosity (fraction)”)
ax.set_ylabel(”Count”)
plt.show()Other options include "scott", "sturges" and "auto".
These rules are useful because they respond to the data rather than applying the same arbitrary bin count to every variable.
However, they should be treated as starting points and worked on from there.
A bin-width rule attempts to balance resolution against sampling noise, however, it does not know whether twe are trying to investigate skewness, tails, outliers or multiple geological populations.
It can still produce a reasonable histogram whilst obscuring the particular feature you care about.
Bin Position Matters Too
Bin count is often the choice most will go to when changing parameters on a histogram, however, the less obvious choice is where the bin boundaries begin.
Two histograms can use exactly the same bin width and still look different because their bin boundaries begin in different positions. Shifting the first boundary shifts every subsequent boundary with it. Values near an edge may then move from one bar to another, changing the heights of neighbouring bins.
In the following example, the bin width remains fixed at 0.018. The second histogram shifts the boundaries by half a bin width.
width = 0.018
offsets = [0.0, width / 2]
fig, axes = plt.subplots(
1,
2,
figsize=(10, 4.2),
sharey=True
)
for ax, offset in zip(axes, offsets):
edges = np.arange(
plot_range[0] + offset - width,
plot_range[1] + width,
width
)
ax.hist(por, bins=edges)
ax.set_xlim(plot_range)
ax.set_xlabel(”Porosity (fraction)”)
axes[0].set_title(”Original bin alignment”)
axes[1].set_title(”Shifted by half a bin”)
axes[0].set_ylabel(”Count”)
plt.tight_layout()
plt.show()
Both histograms still contain evidence of two modes, but the apparent shape changes.
The relative heights of the peaks differ, as does the depth and position of the valley between them. One alignment produces sharper individual bars, whilst the other gives the populations a broader appearance.
Nothing about the observations has changed. Only the location of the bin boundaries has moved.
For a clearly separated distribution, this may alter only the visual emphasis. For a borderline case with more strongly overlapping populations, the shift may be enough to determine whether a small valley appears at all.
Bin position is particularly easy to overlook because it is rarely stated on the finished figure. The reader sees the bars, but not the arbitrary grid that produced them.
Can We Avoid Binning?
One way to check the distribution is to compare the histogram with a plot that does not use bins.
The empirical cumulative distribution function, or ECDF, plots each observed value against the proportion of observations at or below it.
xs = np.sort(por)
ys = np.arange(1, len(xs) + 1) / len(xs)
fig, ax = plt.subplots(figsize=(6, 4.5))
ax.plot(
xs,
ys,
drawstyle=”steps-post”
)
ax.set_xlim(plot_range)
ax.set_ylim(0, 1)
ax.set_xlabel(”Porosity (fraction)”)
ax.set_ylabel(”Cumulative proportion”)
plt.show()
The ECDF has no bin count, bin width or bin origin. Every observation contributes directly to the curve.
It is particularly useful for reading quantiles, comparing distributions and understanding the proportion of values above or below a threshold.
Changes in concentration can also appear as changes in slope. Steeper sections indicate that many values occupy a relatively narrow interval, whilst shallower sections indicate that the observations are more dispersed.
However, an ECDF is not necessarily the best plot for identifying modes.
The two concentrations are visible through changes in the slope of the curve, but they are less immediate than the peaks in a well-chosen histogram. Someone unfamiliar with ECDFs may find the histogram much easier to interpret.
It is therefore better viewed as a complementary plot rather than a complete alternative.
Kernel density estimates offer another smooth view of a distribution without discrete bins, but they introduce a bandwidth parameter. Too much smoothing can merge populations, whilst too little can produce artificial bumps. Kernel density plots avoid discrete bins, but they still require us to choose how much smoothing to apply.
A More Reliable Way to Use Histograms
When working with histograms, there are a few things we can do to settle on the most optimal bin parameters for the figure we are working on:
Plot several reasonable bin counts whilst keeping the plotting range fixed.
Try shifting the bin origin, particularly when a possible mode depends on one or two bars.
Use an automatic rule such as Freedman–Diaconis as a starting point, and work from there
Compare the result with an ECDF, density estimate, rug plot or the known geological groupings.
Known categories are especially important.
If formation labels are available, plotting each formation separately may reveal that two overlapping geological populations produce only one broad peak in the combined data.
The Histogram Is Still Useful
A histogram remains one of the fastest ways to obtain a first impression of a continuous variable. It can reveal skewness, unusual tails, gaps and possible modes in a form that most readers understand immediately.
However, the danger begins when we forget that its shape depends partly on decisions that we make with the parameters. Bin count controls how much structure is resolved. Bin position determines which observations are grouped together.
Neither the bin count nor the bin position comes from the underlying data, but both can change how we interpret the final plot.
The histogram’s blind spot isn’t unique to histograms. Every standard chart compresses the data somehow, and each has a point where the thing it compresses away is the thing you needed to see. Over on Substack I walk through nine common scientific plots and the single blind spot that trips each one up, from scatter plots and boxplots to correlation matrices and PCA.


