From: John Hunter <jdh2358@gm...>  20091201 03:22:53

On Mon, Nov 30, 2009 at 6:44 PM, William Carithers <wccarithers@...> wrote: > I would like to fit a gaussian to a histogram and then overplot it. I can > write the code to do this but most plotting packages support such fitting. > However I can't find it for pyplot even after scanning documentation, > googling, etc. In fact, the only fitting functionality I could find was the > polynomial fitting for numpy that is layered underneath matplotlib, i.e. > Numpy.polyfit(...). > > Does anyone know if/how this might be built into matplotlib? For a Gaussian distribution, the best fit is provided by the normal distribution which has the same mean and stddev as your empirical data (this is not true in general for other distributions). Once you have the mean and stddev from the data, you can use normpdf to plot the analytic density  see for example http://matplotlib.sourceforge.net/search.html?q=normpdf For more powerful density fitting and sampling, see scipy.stats functions, eg scipy.stats.norm.fit JDH 