MathGroup Archive 1999

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

Search the Archive

Re: Gaussian PDF Overlay

  • To: mathgroup at smc.vnet.net
  • Subject: [mg19297] Re: [mg19277] Gaussian PDF Overlay
  • From: "Tomas Garza" <tgarza at mail.internet.com.mx>
  • Date: Sat, 14 Aug 1999 01:45:20 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Lawrence Walker [lwalker701 at earthlink.net] wrote:

> 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?

Use GeneralizedBarChart instead of BarChart. This allows you to fix the
position of the bars, as well as their height and width:

In[1]:=
<< Statistics`NormalDistribution`;
<< Graphics`Graphics`;
<< Statistics`DataManipulation`;
In[2]:=
gauss := Random[NormalDistribution[]];
data = Table[gauss, {7000}];
cutoffs = Range[-4, 4, .2];
freq = BinCounts[data, {-4, 4, .2}];
midpts = Drop[cutoffs + .1, -1];
In[8]:=
bchart = GeneralizedBarChart[Transpose[{midpts, freq, Table[0.05, {40}]}],
      PlotRange -> All, BarLabels -> None, DisplayFunction -> Identity];
In[9]:=
PlotCharts[mu_, sigma_, scale_] := (
    plt = Plot[Evaluate[scale
PDF[NormalDistribution[mu, sigma], x]], {x, -4, 4},
        PlotRange -> All, DisplayFunction -> Identity];
    Show[plt, bchart, DisplayFunction -> $DisplayFunction]);
In[11]:=
PlotCharts[0, 1, 1400]

This does what you want.

Tomas Garza
Mexico City



  • Prev by Date: Re: circumference of an ellipse
  • Next by Date: Re: circumference of an ellipse
  • Previous by thread: Re: Gaussian PDF Overlay
  • Next by thread: Re: Re: Gaussian PDF Overlay