注意,在上面的例子中confid_95_list
是已經錯誤的列表。所以沒有必要從劇情中獲得它們。
要回答這個問題:在行for bar in bar_list
,bar
是一個Rectangle
,因此沒有與它關聯的錯誤欄。
但是bar_list
是一個條形容器,其屬性爲errorbar
,其中包含錯誤欄創建的返回。然後您可以獲得線路集合的各個部分。每條線從yminus = y - y_error
到yplus = y + y_error
;線路集合僅存儲點yminus
,yplus
。舉個例子:
means = (20, 35)
std = (2, 4)
ind = np.arange(len(means))
p = plt.bar(ind, means, width=0.35, color='#d62728', yerr=std)
lc = [i for i in p.errorbar.get_children() if i is not None][0]
for yerr in lc.get_segments():
print (yerr[:,1]) # print start and end point
print (yerr[1,1]- yerr[:,1].mean()) # print error
將打印
[ 18. 22.]
2.0
[ 31. 39.]
4.0
所以這很適合symmectric errorbars。對於不對稱誤差線,您還需要考慮這一點。
means = (20, 35)
std = [(2,4),(5,3)]
ind = np.arange(len(means))
p = plt.bar(ind, means, width=0.35, color='#d62728', yerr=std)
lc = [i for i in p.errorbar.get_children() if i is not None][0]
for point, yerr in zip(p, lc.get_segments()):
print (yerr[:,1]) # print start and end point
print (yerr[:,1]- point.get_height()) # print error
將打印
[ 18. 25.]
[-2. 5.]
[ 31. 38.]
[-4. 3.]
這似乎過於複雜結束,因爲你只檢索您最初投入,means
和std
值,你可以簡單地使用任何你想要的值做。