 # plotting asymmetric error bars?

hi all,

i am trying to plot asymmetric yaxis error bars. i have the following code:

import matplotlib.pyplot as plt
a = array([[ 0.5, 1.5],
[ 0.7, 2.2],
[ 2.8, 3.1]])
plt.errorbar([1,2,3],[1,2,3],yerr=a)

where each element in the list represents the -yerror, +yerror, like
the documentation for plt.errorbar asks for. when i try to plot this,
i get the following error:

/Library/Python/2.5/site-packages/matplotlib/axes.pyc in vlines(self,
x, ymin, ymax, colors, linestyles, label, **kwargs)
3271
3272 verts = [ ((thisx, thisymin), (thisx, thisymax))
-> 3273 for thisx, (thisymin,
thisymax) in zip(x,Y)]
3274 #print 'creating line collection'
3275 coll = mcoll.LineCollection(verts, colors=colors,

ValueError: too many values to unpack

any idea what's causing this?

the only way it lets me plot is if i do:

plt.errorbar([1,2,3],[1,2,3],yerr=[a[:, 0], a[:, 1]])

which is not the intended result, since the first column in a is the
-yerror and the second is +yerror. does anyone know how to fix this?

thank you.

Hi Per,

You need 2*N, not N*2 arrays here. I think you're also trying to use absolute values so you probably need something like this:

plt.errorbar([1,2,3],[1,2,3],yerr=np.abs(a.T-[1,2,3]))

I hope this is what you're after,

Gary R.

per freem wrote:

hi all,

i am trying to plot asymmetric yaxis error bars. i have the following code:

import matplotlib.pyplot as plt
a = array([[ 0.5, 1.5],
[ 0.7, 2.2],
[ 2.8, 3.1]])
plt.errorbar([1,2,3],[1,2,3],yerr=a)

<snip>