2015-12-02 23 views
1

我創建了一個直方圖來查看列表中相似值的數量。如何在直方圖上添加錯誤欄?

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,但是這給了我一個錯誤。

對不起,我是初學者!謝謝!

回答

0

ax.hist返回倉邊緣和頻率(n),因此我們可以使用那些xy在調用errorbar。此外,的bins輸入採用一個整數表示bin數或一個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') 
相關問題