将直方图与泊松分布和高斯曲线进行比较

Compare Histogram to Poisson Distribution and Gauss-Curve

我得到了100个实验值:

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])

现在我想将其与泊松分布和高斯分布进行比较。 我想将曲线放在直方图的顶部:

但是没用。 例如使用泊松分布:我想拟合覆盖直方图的泊松分布

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)

但是当我绘制它时,它甚至还差得远

plt.plot(x_plot, poisson(x_plot, *parameters), 'r-', lw=2)

你会如何解决这样的问题?我认为是因为我的价值观太高了。泊松区以 k = 0, 1, 2, .... 运行 我的就像 k' = 6000, 6200, ...

在你的图中有一条红线...它是泊松曲线。你用的是什么拉姆达?它很可能太小,你只会得到零。 无论如何,我建议您使用:poisson 来自 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)

您还应该将 normed=True 添加到您的第一个直方图

entries, bin_edges, patches = plt.hist(N, bins=b, weights=w, normed=True)