2012-10-29 51 views
7

我需要繪製條形圖不對稱誤差棒...matplotlib酒吧不對稱誤差條

的matplotlib.pyplot.bar函數的文檔說:

Detail: xerr and yerr are passed directly to errorbar(), so they can also have shape 2xN for independent specification of lower and upper errors.

但是,我可以不給一個2×N個排列到yerr ...

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數組嗎? 如果答案是肯定的......我如何繪製一個帶有不對稱誤差線的條形圖?

謝謝你的時間!

回答

9

您正在使用哪個版本的matplotlib?

隨着1.1.1(最新版本)的版本,您的代碼完美無瑕。

+0

我有0.99.3版本...我gona編譯1.1.1,非常感謝! – Geparada

+0

已解決!謝謝。 – Geparada