# 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!

## Answers

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