我有一些数据点是一个变量的函数。我想绘制这些,但每个数据都有相关的不确定性。误差线是可以的,但我希望能够可视化我们期望误差分布的方式。例如,可以给出一个已知宽度的高斯分布。
我希望 fill_between 的 alpha 值可以根据概率分布进行设置,从而产生类似于这个问题中关于在曲线下填充的图,而是根据高斯在上方和下方用 alpha 进行着色。
我想可能有一些方法可以破解 fill_between 来完成这项工作,但到目前为止我无法弄清楚。这是我到目前为止所拥有的,任何人都可以更优雅地做到这一点吗?
# example x data, y data, and uncertainties
def exampleFunc(x):
return np.sin((x/1.5-3.0)**2)+1.0
xdata = np.linspace(0,10,100)
ydata = exampleFunc(xdata)
# define this data to be gaussian distributed with these standard
# deviations
uncertainties = np.sqrt(ydata)
fig, ax = pl.subplots()
# plot the data centers on a line
ax.plot(xdata, ydata, 'b') # blue to stand out from shading
numsigma = 5 # how many standard deviations to go out
numsteps = 100 # how many steps to take in shading
# go to shade the uncertainties between, out to 4 sigma
for i in range(1,numsteps+1):
top = ydata + uncertainties/numsteps*i*numsigma
bottom = ydata - uncertainties/numsteps*i*numsigma
ax.fill_between(xdata, bottom, top, color='r',
alpha=1.0/numsteps)