# How to extract the bin width from a Histogram made with an automatic binning method?

I am using the Scott binning method with Histogram and Histogram3D to plot some data. How could I find out the bin width chosen by Mathematica?

I am using version 7 and thus I cannot use HistogramList.

• Please see the edit to my answer for a version 7 solution. – rm -rf Mar 22 '13 at 18:54

In version 8 and above, HistogramList will give you a list of bin delimiters and counts, so you need to just pass it the same options you pass to Histogram and Histogram3D. For example,

{bins, counts} = HistogramList[RandomVariate[NormalDistribution[0, 1], 200], "Scott"]
(* {{-(7/2), -3, -(5/2), -2, -(3/2), -1, -(1/2), 0, 1/2, 1, 3/2, 2},
{1, 0, 5, 10, 16, 34, 39, 40, 39, 9, 7}} *)

For version 7, which does not have HistogramList, you can generate the histogram and get the bin info from the rectangles used in the plot. For example,

histogramList[x_] := Transpose@Cases[x, RectangleBox[{bl_, _},{br_, c_}] :> {{bl, br}, c}, ∞];
hist = Histogram[RandomReal[NormalDistribution[0, 1], 200], "Scott"];
{bins, counts} = histogramList@hist

(* {{{-3, -(5/2)}, {-(5/2), -2}, {-2, -(3/2)}, {-(3/2), -1}, {-1, -(1/2)}, {-(1/2), 0},
{0, 1/2}, {1/2, 1}, {1, 3/2}, {3/2, 2}, {2, 5/2}, {5/2, 3}},
{2, 3, 13, 19, 29, 34, 40, 28, 19, 10, 2, 1}} *)

Note that the above gives you the bin interval pairs, instead of just the delimiters. If you want it in the same format as HistogramList in version 8, then just use Flatte@DeleteDuplicates on bins.