Histogram: how to make one and choose the number of bins
A histogram shows how a column of measurements is distributed. It splits the range of the data into adjacent intervals of equal width, called bins, and draws a bar over each bin as tall as the number of values that fall in it. It answers questions that a mean and a standard deviation cannot: is the process centered on target, is the spread symmetric or skewed, is there one peak or two, and do any values sit far from the rest?
When to use it
- You have about 30 or more measurements of one continuous variable, such as a diameter, a weight or a cycle time. With fewer, a dotplot or an individual value plot shows the data more honestly.
- You are about to run a capability analysis and want to see the shape and centering against the specification limits first.
- You suspect a mixture in one column: two machines, two mold cavities, two suppliers or two shifts.
How it works
- Find the smallest and largest values.
- Choose the number of bins k, or the bin width h. The edges start at a round number at or below the minimum.
- Count the values in each bin. A value that falls exactly on an edge goes to the bin it starts.
- Draw the bars touching each other, because the scale is continuous.
The vertical axis can show counts, percentages, or density (count divided by n × h), which makes the total area of the bars equal to 1. Density is the right scale when you overlay a fitted curve or compare samples of different sizes.
The bin choice is the one real decision. Four common rules give a starting point:
Sturges: k = 1 + log₂ n
Square root: k = √n
Freedman-Diaconis: h = 2 × IQR × n^(−1/3)
Scott: h = 3.49 × s × n^(−1/3)Here IQR is the interquartile range (Q3 − Q1) and s the sample standard deviation. Round the result to a convenient width, such as 0.05 or 0.1, and make it a whole multiple of the measurement resolution. Sturges and Scott assume a roughly bell-shaped sample; Freedman-Diaconis uses the IQR so that outliers do not stretch the bins. No rule is right for every dataset, so treat them as a first try.
Example
A two-cavity mold makes a plastic clip with a target weight of 25.10 g and limits of 24.70 to 25.50 g. A technician weighs 60 clips in the order they leave the press, so the cavities alternate. The 60 weights have a mean of 25.090 g, a standard deviation of 0.138 g, and run from 24.85 to 25.32 g.
The rules suggest:
- Sturges: 1 + log₂ 60 = 6.9, so 7 bins.
- Square root: √60 = 7.7, so 8 bins.
- Freedman-Diaconis: Q1 = 24.97 and Q3 = 25.22 by the (n + 1)p rule, so IQR = 0.25 g and h = 2 × 0.25 × 60^(−1/3) = 0.128 g, about 4 bins across the 0.47 g range.
- Scott: h = 3.49 × 0.138 × 60^(−1/3) = 0.123 g, also about 4 bins.
With 10 bins, the histogram shows two separate peaks:
No clip weighed between 25.06 and 25.13 g, and the target sits right in that gap. Splitting the data by cavity explains it: cavity 1 averages 24.960 g with a standard deviation of 0.042 g, and cavity 2 averages 25.219 g with 0.045 g. Each cavity on its own is narrow; the overall standard deviation of 0.138 g is three times larger because of the 0.26 g offset between them.
The same data in 4 equal bins from 24.85 to 25.32 g, about the width the Freedman-Diaconis and Scott rules suggest, hold 14, 16, 11 and 19 values: a flat block with no hint of two cavities.
Two peaks inflate the IQR and the standard deviation, so the spread-based rules ask for wide bins, which hide the peaks. The fix here is not to reduce the overall variation but to bring the two cavities to the same weight.
How to read the results
- Center. Is the tallest part of the histogram on the target, or off to one side?
- Spread. Compare the width of the bars with the distance between the limits. Bars close to a limit mean a capability problem even if no part is out yet.
- Shape. A single symmetric hump is typical of a stable process. A long tail on one side is normal for features bounded by zero, such as runout or flatness. Two peaks point to a mixture of two sources. A flat top can come from drift or tool wear during the sample. A sharp cliff at a specification limit usually means the parts beyond it were sorted out.
- Isolated bars. A bar far from the rest may be a recording error, a measurement problem or a real special cause.
- Gaps in a comb pattern. Regularly empty bins usually mean the bin width does not match the measurement resolution, or the data are too coarse; see the chunky-data check.
Common mistakes
- Trusting one binning. Try two or three widths before you conclude anything about the shape.
- Comparing histograms drawn with different bins or axes. Use the same edges and the same scale for before-and-after comparisons.
- Looking for time patterns. A histogram throws away the order of the data. A drifting process and a stable one can give the same histogram; use a run chart or a control chart for that.
- Reading shape from very small samples. With 20 values, random bumps look like real features.
- Treating a bell shape as proof of normality. Use a probability plot or a normality test.
Frequently asked questions
How many bins should a histogram have?
Start with the Sturges or square-root rule (about 7 to 10 bins for 50 to 100 values) and adjust. Too few bins hide features; too many turn every bar into a random bump.
What is the difference between a histogram and a bar chart?
A histogram shows the distribution of one continuous variable, so its bars touch and their order is fixed by the scale. A bar chart compares separate categories, such as defect types or lines, so its bars stand apart and can be sorted.
How many data points do I need for a histogram?
About 30 is a practical minimum; 50 to 100 is better. Below 30, use a dotplot.
What does a histogram with two peaks mean?
Usually that the data come from two sources with different averages: two cavities, machines, operators, material lots or gauges. Split the data by the likely source and plot each group on its own.