1

How would I be able to plot a Gaussian on top of the histogram my code generates? Here is my code below. It works perfectly and generates a histogram but I'm struggling with adding a Gaussian curve as I've only just started using pyplot. I'm also struggling with the maths involved!

noodle
  • 19
  • 1
  • 2
  • 9
  • See http://stackoverflow.com/questions/20011122/fitting-a-normal-distribution-to-1d-data/20012350#20012350 – Warren Weckesser May 08 '15 at 17:33
  • Usually you don't edit the post to put [SOLVED] in the title on here (see e.g http://meta.stackexchange.com/questions/116101/is-it-ok-to-add-solved-to-the-title-of-a-question and its answers), and I would leave the code you had in the post for the benefit of anyone who looks at the question in the future. It's easy to roll back the edit to the previous version from this page http://stackoverflow.com/posts/30129355/revisions. Would you do that? – J Richard Snape May 08 '15 at 21:38

1 Answers1

1

You probably want to use numpy to generate a Gaussian, and then simply plot it on the same axes. There is a good example here:
Fitting a Gaussian to a histogram with MatPlotLib and Numpy - wrong Y-scaling?

If you actually want to automatically generate a fitted gaussian from the data, you probably need to use scipy curve_fit or leastsq functions to fit your data, similar to what's described here: gaussian fit with scipy.optimize.curve_fit in python with wrong results

Community
  • 1
  • 1
jwinterm
  • 334
  • 3
  • 11