2012-10-29 15 views
7

ho bisogno di tracciare un grafico a barre con barre di errore asimmetriche ...bar matplotlib con barre di errore asimmetriche

La documentazione della funzione matplotlib.pyplot.bar dice:

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

Ma, posso non dare una matrice 2xN al 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! 

e mi mostra il seguente errore:

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 

Ma, invece questa funzione:

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

funziona bene.

Il file matplotlib.pyplot.bar non supporta più gli array 2xN per yerr? Se il risponditore è sì ... Come posso tracciare un grafico a barre con barre di errore asimmetriche?

Grazie per il vostro tempo!

risposta

9

Quale versione di matplotlib stai usando?

Con la versione 1.1.1 (ultima versione stabile) il tuo codice funziona in modo impeccabile.

+0

Ho la versione 0.99.3 ... Sto compilando la 1.1.1, grazie mille! – Geparada

+0

RISOLTO! grazie. – Geparada

Problemi correlati