Histogram Bin Width

The bin width of a histogram is the size of the interval each bar covers. It determines how many observations land in each bar, and with that, how much of the shape you see is structure in the data and how much is sampling noise.

It is an analytical choice, not a display setting. The same observations binned two ways support different claims — a smooth unimodal hump at one width, a run of separate peaks at another — so the width is part of the finding, and worth reporting alongside it.

Common defaults derive the width from sample size and spread. Sturges uses log2(n) + 1 bins; Scott uses σ·∛(24√π/n), whose coefficient is the familiar 3.49; Freedman–Diaconis uses 2·IQR/∛n, which is more robust because the interquartile range resists outliers. numpy’s auto takes the larger bin count of Sturges and FD.

What they share is an assumption: one sample drawn from a fixed, reasonably smooth distribution. numpy’s documentation is explicit that Sturges is “only optimal for gaussian data” and “underestimates number of bins for large non-gaussian datasets”, while FD “can be too conservative for small datasets”. For timestamps spread across a fixed observation window, the spread is roughly the window length no matter how the underlying rate behaves inside it, so these inputs carry little information about the structure being looked for.

The alternative is to choose the width by minimizing an estimate of the error the histogram makes against the unobserved truth. That turns bin width from a convention into something the data decide — and, usefully, lets the procedure report that no width resolves anything.

References: numpy.histogram_bin_edges. See it in use in Choosing Histogram Bins for Time-Indexed Events.


Discover more from Insightful Data Lab

Subscribe to get the latest posts sent to your email.

Similar Posts

Questions, corrections, or additional insights?

This site uses Akismet to reduce spam. Learn how your comment data is processed.