Re: Histogram ignores 'bspec' (bin spec) ??

*To*: mathgroup at smc.vnet.net*Subject*: [mg126761] Re: Histogram ignores 'bspec' (bin spec) ??*From*: "Nasser M. Abbasi" <nma at 12000.org>*Date*: Tue, 5 Jun 2012 04:53:33 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*References*: <jqhr60$klr$1@smc.vnet.net>*Reply-to*: nma at 12000.org

On 6/4/2012 3:21 AM, James Stein wrote: > I would like to plot a histogram with a fixed number of bars, e.g. ten bars. > Consider this code: > > SeedRandom [ 1 ] ; > foo = RandomVariate [ NormalDistribution [ 0, 1], 1000 ] ; > baz = Table [ Histogram [ foo, k ], { k, 8, 15 } ] ; > 1 == Length [ DeleteDuplicates [ baz ] ] > > The last line prints 'True', confirmed by visual inspection of baz which > reveals eight identical histograms, each containing 13 bins. What do I fail > to understand here? > > I am not sure why the same bins show up each time. But the way I would do this, at least for now, is to use {dx} and not n for bspec. This way I know exactly the bin width I want to use. Something like this ----------------------- SeedRandom[1]; foo = RandomVariate[NormalDistribution[0,1],1000]; max = Max[foo]; min = Min[foo]; wid = max-min; baz = Table[Histogram[foo,{wid/(k-1)},"PDF"],{k,8,15}] ---------------------- I used PDF above just to get the total area =1 that is all. It is not needed otherwise. now 1 == Length[DeleteDuplicates[baz]] gives False. Note that total width of the data is less than 8 (99.9999% of the time, i.e. 4 standard deviations each side gives 4. So data goes from -4 to 4 since you used NormalDistribution with zero mean and std=1). Not sure if Mathematica has used '1' for the width of each bin when using just 'n'. So 8 bins or more will result in the same data being binned into only first 8 bins (anything over 8 bins will have zero elements, hence might not show in the plot). This might explain why all plots has 8 bins. Not sure. But either way, using {dx} seems safer until some expert here can explain this better. --Nasser