For an assignment I'm asked to plot, in front of a histogram, the histogram of a gaussian distribution. The question is simple, as I already know how to plot the gaussian on top of histograms (and also how to plot histograms).
I already have this:
#bins=array that indicates the boundaries of the bars
#array is an object with attributes such as; standard deviation (stdv); mean or average (mean).
In [63]: 1/(array.stdv*np.sqrt(2*np.pi))*np.exp(-(bins-array.mean)**2/(2*array.stdv**2))
Out[63]:
array([ 1.46863468e-03, 1.71347711e-03, 1.99065837e-03, ...,
5.37698408e-15, 3.25989619e-15, 1.96798911e-15])
In [64]: bins
Out[64]: array([ 33., 34., 35., ..., 187., 188., 189.])
When I try to plot with this, i get:
In [59]: plt.hist(1/(array.stdv*np.sqrt(2*np.pi))*np.exp(-(bins-array.mean)**2/(2*array.stdv**2)),bins,range=(min(histmain.array),max(histmain.array)),histtype='step')
Out[59]:
(array([ 0., 0., 0., ..., 0., 0., 0.]),
array([ 33., 34., 35., ..., 187., 188., 189.]),
<a list of 1 Patch objects>)
[Figure][1]
I think I already know the problem, though. I guess the hist function receives an array of data, and it plots according to the frequencies. What I have is an array of the frequencies. I tried multiplying the function by 3200, but what I got was this atrocity:
In [61]: plt.hist(3200/(array.stdv*np.sqrt(2*np.pi))*np.exp(-(bins-array.mean)**2/(2*array.stdv**2)),bins,range=(min(histmain.array),max(histmain.array)))
Out[61]:
(array([ 1., 1., 0., ..., 0., 0., 0.]),
array([ 33., 34., 35., ..., 187., 188., 189.]),
<a list of 156 Patch objects>)
[Figure][2]
All of the above is without the histogram of data showed.
So sorry. I didn't notice the images weren't displaying. Here's a link to them:
Figure 1 is the flat one. Figure 2 is the horrendous one. What I want to accomplish is a gaussian-like histogram.