Matplotlib 如何在直方图上添加错误条?

Matplotlib 如何在直方图上添加错误条?,matplotlib,histogram,errorbar,Matplotlib,Histogram,Errorbar,我创建了一个直方图来查看列表中相似值的数量 data = np.genfromtxt("Pendel-Messung.dat") stdm = (np.std(data))/((700)**(1/2)) breite = 700**(1/2) fig2 = plt.figure() ax1 = plt.subplot(111) ax1.set_ylim(0,150) ax1.hist(data, bins=breite) ax2 = ax1.twinx() ax2.set_ylim(0,150

我创建了一个直方图来查看列表中相似值的数量

data = np.genfromtxt("Pendel-Messung.dat")
stdm = (np.std(data))/((700)**(1/2))
breite = 700**(1/2)

fig2 = plt.figure()
ax1 = plt.subplot(111)
ax1.set_ylim(0,150)
ax1.hist(data, bins=breite)
ax2 = ax1.twinx()
ax2.set_ylim(0,150/700)

plt.show()

我想在直方图的每个条的中间创建误差条(误差为STDM)。我知道我可以使用

plt.errorbar("something", data, yerr = stdm) 
如何让它们在每个栏中间开始?我本想添加breite/2,但这给了我一个错误


对不起,我是初学者!谢谢大家!

ax.hist
返回存储箱边缘和频率(
n
),因此我们可以在调用
errorbar
时使用
x
y
。此外,
bin
输入到
hist
的值为bin的数量取整数,或为bin的边序列取整数。我想你是想给一个箱子的宽度
breite
?如果是这样的话,这应该是可行的(您只需要选择一个合适的
xmax
):


ax.hist
返回箱子边缘和频率(
n
),因此我们可以在调用
errorbar
时使用
x
y
的边缘和频率。此外,
bin
输入到
hist
的值为bin的数量取整数,或为bin的边序列取整数。我想你是想给一个箱子的宽度
breite
?如果是这样的话,这应该是可行的(您只需要选择一个合适的
xmax
):

n,bin_edges,patches = ax.hist(data,bins=np.arange(0,xmax,breite))

x = bin_edges[:-1]+breite/2.

ax.errorbar(x,n,yerr=stdm,linestyle='None')