0

I am getting the error below when I try to plot the error bar of some data I read from a csv file using pandas read_csv.

ax.errorbar(x1, y1, yerr = std1, marker='d',color='y', label='y1')
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 5762, in errorbar
xo, _ = xywhere(x, lower, everymask)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 5669, in xywhere
assert len(xs) == len(ys)
AssertionError

the code I used is:

 ress=pd.read_csv('/path/myfile', delimiter=',',skiprows=[0],header=None,dtype=None)
 x1=ress[[0]]
 y1=ress[[3]]
 std1=ress[[4]]

 ax=plt.subplot(111)
 ax.errorbar(x1,y1,yerr=std1,marker='d',color='y',label='y1')

I thought at first that x1 and y1 aren't of the same dimensions so I printed x1.shape, y1.shape, and std1.shape and all of them where (11,1). P.S. (11,1) is a correct way of representing my data.

Do you know why I am getting this error?

Thanks in advance

1
  • Can you print x1, y1, and std1 and show their content here. Commented Nov 27, 2015 at 22:41

1 Answer 1

1

The error message is a little misleading here. Because you're using

x1 = ress[[0]]

instead of

x1 = ress[0]

etc., you're passing errorbar a DataFrame (a 2D object of shape (11,1)) instead of a Series (a 1D object of shape (11,)). This is confusing matplotlib. Remove the extra brackets and it should work. For example, we have

>>> ress = pd.DataFrame({0: range(15,20), 3: range(5), 4: [2]*5})
>>> x1 = ress[[0]]
>>> y1 = ress[[3]]
>>> std1 = ress[[4]]
>>> ax = plt.subplot(111)
>>> ax.errorbar(x1,y1,yerr=std1.values,marker='d',color='y',label='y1')
Traceback (most recent call last):
[...]
    assert len(xs) == len(ys)
AssertionError

but

>>> x1,y1,std = ress[0], ress[3], ress[4]
>>> ax = plt.subplot(111)
>>> ax.errorbar(x1,y1,yerr=std1.values,marker='d',color='y',label='y1')
<Container object of 3 artists>

example errorbar plot

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.