MathGroup Archive 1999

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

Search the Archive

Re: Gaussian PDF Overlay

  • To: mathgroup at
  • Subject: [mg19283] Re: [mg19277] Gaussian PDF Overlay
  • From: BobHanlon at
  • Date: Sat, 14 Aug 1999 01:45:11 -0400
  • Sender: owner-wri-mathgroup at


Use a GeneralizedBarChart:


dist = NormalDistribution[mu = 4., sigma = 2.];

xmin = mu - 3sigma; xmax = mu + 3sigma;

plt1 = Plot[PDF[dist, x], {x, xmin, xmax}, PlotStyle -> AbsoluteThickness[2], 
      DisplayFunction -> Identity];

nbrSamples = 1000;
data = RandomArray[dist, nbrSamples];
nbrBins = 10;
step = (xmax - xmin)/nbrBins;
freq = BinCounts[data, {xmin, xmax, step}]/nbrSamples;
midPoints = Table[xmin + step(k - 1/2), {k, nbrBins}];

plt2 = GeneralizedBarChart[Transpose[{midPoints, freq, Table[1, {nbrBins}]}], 
      DisplayFunction -> Identity];

Show[{plt2, plt1}, DisplayFunction -> $DisplayFunction];

Bob Hanlon

In a message dated 8/12/99 5:35:54 AM, lwalker701 at writes:

>I've tried to overlay a continuous gaussian probability
>density curve onto a bar chart of similar distribution.  The
>values for the barchart were generated by bin counting the
>data using the BinCounts function.  The data is a list
>generated by Random[NormalDistribution[]].
>At first I simply tried to overlay the plot and barchart
>using Show.  The x-axis scale of the curve was different
>from the 
>barchart's scale.  So I had to manually change the position
>and rescale the curve until it overlayed the barchart using
>the program below.  I didn't like the fact that the x-scale
>shows 0 to 40 instead of -4 to 4.
>Is there a better way of doing this?

  • Prev by Date: Re: Subscripts, Doh!!!
  • Next by Date: Re: Please Help
  • Previous by thread: Gaussian PDF Overlay
  • Next by thread: Re: Gaussian PDF Overlay