简体   繁体   中英

How to plot a gaussian over histogram

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM