Re: Re: How to get data from Histogram

• To: mathgroup at smc.vnet.net
• Subject: [mg97481] Re: [mg97455] Re: [mg97367] How to get data from Histogram
• From: Brett Champion <brettc at wolfram.com>
• Date: Sat, 14 Mar 2009 05:36:55 -0500 (EST)
• References: <200903130953.EAA20401@smc.vnet.net>

```On Mar 13, 2009, at 4:53 AM, Bob Hanlon wrote:

> h = Histogram[RandomReal[NormalDistribution[0, 1], 200]]
>
> Just look at the FullForm and extract whatever you want. The bin
> interval and count are
>

The method used in the documentation, as pointed out by DrMajorBob is
better.  It gets the information from a documented behavior of
Histogram (namely, what the third argument can be.)

The internal form of the graphic returned by Histogram is not
documented and is subject to change from version to version.  For
example, V7.0.1 has a change from V7.0.0 in how the styles are applied
to Histogram's bars so that the size (in bytes) of the graphic is
smaller (by about 20% for a simple example I just tried.)

Brett Champion
Wolfram Research

> bd = Cases[h, RectangleBox[{bl_, _}, {br_, c_}] :> {{bl, br}, c},
> Infinity]
>
> {{{-(5/2), -2}, 5}, {{-2, -(3/2)}, 8}, {{-(3/2), -1}, 13},
>   {{-1, -(1/2)}, 36}, {{-(1/2), 0}, 37}, {{0, 1/2}, 43},
>   {{1/2, 1}, 23}, {{1, 3/2}, 21}, {{3/2, 2}, 7}, {{2, 5/2}, 5},
>   {{5/2, 3}, 2}}
>
> bins = bd[[All, 1]] // Flatten // Union
>
> {-(5/2), -2, -(3/2), -1, -(1/2), 0, 1/2, 1, 3/2, 2, 5/2, 3}
>
> counts = bd[[All, 2]]
>
> {5,8,13,36,37,43,23,21,7,5,2}
>
> counts == Cases[h, Tooltip[_, Style[label_, __]] :> label, Infinity]
>
> True
>
>
> Bob Hanlon
>
> ---- Jozef Pulko <jozef.pulko at googlemail.com> wrote:
>
> =============
> Well that is exactly what I was looking for. Thanks!!
>
> SOLUTION:
> h = Histogram[RandomReal[NormalDistribution[0, 1], 200]]
> counts = Cases[h, Tooltip[_, Style[label_, __]] :> label, Infinity]
>
> However I only get number of counts in a bin.. is it possible to
> somehow extract also the bin positions?
>

```

• Prev by Date: Re: Re: Mathematica 7.0.1.0 and some General Comments
• Next by Date: Re: font size
• Previous by thread: Re: How to get data from Histogram
• Next by thread: opening notebooks in mathematica player instead of mathematica