Matplotlib直方图带有误差条 [英] Matplotlib histogram with errorbars
本文介绍了Matplotlib直方图带有误差条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用pyplot.hist()
函数使用matplotlib
创建了直方图.我想将垃圾箱高度(sqrt(binheight)
)的毒害误差平方根添加到条形图.我该怎么办?
I have created a histogram with matplotlib
using the pyplot.hist()
function. I would like to add a Poison error square root of bin height (sqrt(binheight)
) to the bars. How can I do this?
.hist()
的返回元组包括return[2]
-> 1个Patch对象的列表.我只能发现有可能向通过pyplot.bar()
创建的条形添加错误.
The return tuple of .hist()
includes return[2]
-> a list of 1 Patch objects. I could only find out that it is possible to add errors to bars created via pyplot.bar()
.
推荐答案
实际上,您需要使用bar.您可以用来输出hist
并将其绘制为条形图:
Indeed you need to use bar. You can use to output of hist
and plot it as a bar:
import numpy as np
import pylab as plt
data = np.array(np.random.rand(1000))
y,binEdges = np.histogram(data,bins=10)
bincenters = 0.5*(binEdges[1:]+binEdges[:-1])
menStd = np.sqrt(y)
width = 0.05
plt.bar(bincenters, y, width=width, color='r', yerr=menStd)
plt.show()
这篇关于Matplotlib直方图带有误差条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文