Reputation: 1403
I got 100 experimental values:
N = np.array([ 6080, 5604, 5972, 5566, 5683, 5619, 5582, 5912, 5614,5837, 5961, 5972, 5807, 5829, 5881, 5757, 5725, 5809, 5626, 5995, 5793, 5608, 5880, 5982, 5748, 6071, 6181, 6034, 6117, 5903, 6190, 5735, 6109, 6126, 6012, 5948, 6139, 6103, 6108, 6031, 6200, 6091, 6199, 6165, 6591, 5803, 6093, 5921, 6194, 5799, 6020, 6156, 6129, 6344, 6243, 6122, 5926, 5904, 5579, 5881, 6157, 5925, 5835, 5778, 6125, 5737, 5703, 5809, 6109, 5978, 5881, 6250, 6143, 5658, 5815, 5633, 5780, 5620, 6180, 5770, 6058, 5688, 5792, 6170, 5915, 6147, 5727, 6300, 6049, 6263, 6168, 6156, 6071, 6196, 6078, 5848, 5847, 6248, 6243, 6084])
Now I want to compare this with a Poisson-Distribution and Gaussian-Distribution. I want to put the Curves on Top of my histogram:
But it doesn't work. For e.g. with the Poisson-Distribution: I want to make a Fit of Poisson-Distribution which lays over my Histogram
b = np.sqrt(len(N))
w = np.ones_like(N)/float(len(N))
entries, bin_edges, patches = plt.hist(N, bins=b, weights=w)
def poisson(x, lamb):
return (lamb**x/factorial(x)) * np.exp(-lamb)
parameters, cov_matrx = curve_fit(poisson, bin_middles, entries)
But when I plot it, its not even near
plt.plot(x_plot, poisson(x_plot, *parameters), 'r-', lw=2)
How would you solve such a Problem? I think its because my values are too high. The Poisson Distr. runs with k = 0, 1, 2, .... Mine are like k' = 6000, 6200, ...
Upvotes: 2
Views: 1482
Reputation: 465
In your plot there is a red line...it's the Poisson curve. What lambda are you using? It's very likely too small and you get only zeroes. Anyway I suggest you to use: poisson function from scipy
def poisson(x, lamb):
from scipy.stats import poisson as _poisson
return _poisson.pmf(x,lamb)
parameters, cov_matrx = curve_fit(poisson, bin_middles, entries, p0=6000)
You should also add normed=True
to your first histogram plot
entries, bin_edges, patches = plt.hist(N, bins=b, weights=w, normed=True)
Upvotes: 1