[英]matplotlib bar with asymmetrical error bars
我需要繪制一個帶有不對稱誤差條的條形圖...
matplotlib.pyplot.bar函數的文檔說:
細節:xerr和yerr直接傳遞給errorbar(),因此它們也可以具有形狀2xN,用於獨立指定低位和高位錯誤。
但是,我不能給一個2xN陣列...
import numpy as np
import matplotlib.pyplot as plt
plt.bar(xrange(5), [2,5,3,4,7], yerr=[[1,4,2,3,6],[4,10,6,8,14]]) #DO NOT work!
並告訴我以下錯誤:
Traceback (most recent call last):
File "bar_stacked.py", line 9, in <module>
plt.bar(xrange(5), [2,5,3,4,7], yerr=[[1,4,2,3,6],[4,10,6,8,14]])
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 1742, in bar
ret = ax.bar(left, height, width, bottom, color, edgecolor, linewidth, yerr, xerr, ecolor, capsize, align, orientation, log, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 4253, in bar
"incompatible sizes: bar() argument 'yerr' must be len(%s) or scalar" % nbars)
ValueError: incompatible sizes: bar() argument 'yerr' must be len(5) or scalar
但是,相反這個功能:
import numpy as np
import matplotlib.pyplot as plt
plt.errorbar(xrange(5), [2,5,3,4,7], yerr=[[1,4,2,3,6],[4,10,6,8,14]])
工作良好。
matplotlib.pyplot.bar是否不再支持yerr的2xN數組? 如果回答是肯定的...我如何繪制具有不對稱誤差條的條形圖?
謝謝你的時間!
您使用的是哪個版本的matplotlib?
使用1.1.1(最新的穩定版),您的代碼可以完美運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.