MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to get data from Histogram

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97455] Re: [mg97367] How to get data from Histogram
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Fri, 13 Mar 2009 04:53:41 -0500 (EST)
  • Reply-to: hanlonr at cox.net

h = Histogram[RandomReal[NormalDistribution[0, 1], 200]]

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.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: Notebook that auto-executes when opened?
  • Next by Date: Re: General form of a summation as a function of 2
  • Previous by thread: Re: How to get data from Histogram
  • Next by thread: Re: Re: How to get data from Histogram