i am using Mathematica 7.0.0.
what I would like to do is to somehow get data out of histogram generated by
Histogram[].
For an example:
I tried to do find the frequency of my data with BinCounts[]... but I need
to manually chose binsize an binwindow.
By using Histogram[] the binsize and binwindow are chosen automatically with
smart algorithms, but only plotted. is there any way to get data out of
plotted histogram?
Thnx,
Jozef
{g, {binCounts}} =
Reap[Histogram[
RandomReal[NormalDistribution[0, 1], 100], {-2, 2, 0.25},
Function[{bins, counts}, Sow[counts]]]];
binCounts
{{3, 4, 5, 6, 11, 3, 12, 6, 5, 13, 7, 4, 10, 2, 3, 2}}
Bobby
I was trying to get data like it is described in these example...
But this only works if I chose interval and step for histogram. I was not
able to get data out of histogram when letting Mathematica automatically
chose step and interval for building the histogram.
Jozef
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?
Just look at the FullForm and extract whatever you want. The bin interval and count are
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...@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?
> 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
> Thanks for answers, but this didn't solved my problem...
>
> I was trying to get data like it is described in these example...
>
> But this only works if I chose interval and step for histogram. I
> was not
> able to get data out of histogram when letting Mathematica
> automatically
> chose step and interval for building the histogram.
>
This will use the automatic bin selection, and return the bins and
their counts:
{g, {binCounts}} =
Reap[Histogram[
RandomReal[NormalDistribution[0, 1], 100], Automatic,
Function[{bins, counts}, Sow[{bins, counts}];counts]]];
Brett Champion
Wolfram Research