2012-10-29 25 views
7

tôi cần phải vẽ một biểu đồ hình cột với thanh lỗi không đối xứng ...thanh matplotlib với thanh lỗi không đối xứng

Các tài liệu của hàm matplotlib.pyplot.bar nói:

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

Nhưng, tôi có thể không đưa ra một mảng 2xN đế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! 

Và chỉ cho tôi những lỗi sau:

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 

Nhưng, thay vì chức năng này:

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]]) 

trình tốt.

Matplotlib.pyplot.bar có còn hỗ trợ các mảng 2xN cho yerr không? Nếu câu trả lời là có ... Làm thế nào tôi có thể vẽ đồ thị thanh với thanh lỗi không đối xứng?

Cảm ơn bạn đã dành thời gian!

Trả lời

9

Bạn đang sử dụng phiên bản matplotlib nào?

Với phiên bản 1.1.1 (mới nhất) ổn định, mã của bạn hoạt động hoàn hảo.

+0

Tôi có phiên bản 0.99.3 ... Tôi gona biên dịch phiên bản 1.1.1, cảm ơn rất nhiều! – Geparada

+0

GIẢI PHÁP! cảm ơn bạn. – Geparada

Các vấn đề liên quan