Python - 使用Maxwell Distribution绘制置信度误差条

时间:2016-10-07 23:39:57

标签: python numpy scipy

我从未尝试过基于置信区间实现误差线。因为这就是我想做的事情,我不确定如何继续前进。

我有这个包含~1000个元素的大数据数组。通过绘制具有此数据的直方图,它看起来就像Maxwell-Boltzmann分布一样。

假设我的数据名为x,我将其作为

应用
import scipy.stats as stats
import numpy as np
import matplotlib.pyplot as plt

maxwell = stats.maxwell

## Scale Parameter
params = maxwell.fit(x, floc=0)
print params

## mean
mean = 2*params[1]*np.sqrt(2/np.pi)
print mean

## Variance
sig = (params[1])**(3*np.pi-8)/np.pi
print sig

>>> (0, 178.17597215151301)
>>> 284.327714571
>>> 512.637498406

在绘制时

fig = plt.figure(figsize=(7,7))
ax = fig.add_subplot(111)

xd = np.argsort(x)

ax.plot(x[xd], maxwell.pdf(x, *params)[xd])

ax.hist(x[xd], bins=75, histtype="stepfilled", linewidth=1.5, facecolor='none', alpha=0.55, edgecolor='black', 
    normed=True)

enter image description here

你究竟如何在曲线拟合中植入置信区间?

我可以用

conf = maxwell.interval(0.90,loc=mean,scale=sig)
>>> (588.40702793225228, 1717.3973740895271)

但我不知道该怎么做

0 个答案:

没有答案