0

I am trying to plot a errorbar:

plt.errorbar(np.array(x_axis), np.array(y_axis), yerr=(np.array(y_bot), np.array(y_top)), linestyle='None', marker='^')

But it throws an error :

plt.errorbar(np.array(x_axis), np.array(y_axis), yerr=(np.array(y_bot), np.array(y_top)), linestyle='None', marker='^')


File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/pyplot.py", line 2747, in errorbar
    errorevery=errorevery, capthick=capthick, **kwargs)
  File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/axes/_axes.py", line 2792, in errorbar
    barcols.append(self.vlines(xo, lo, uo, **lines_kw))
  File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/axes/_axes.py", line 1067, in vlines
    for thisx, (thisymin, thisymax) in zip(x, Y)]
ValueError: too many values to unpack

x_axis, y_axis, y_bot, x_bot are 1D array of length 4.

5
  • 1
    your code works fine for me, maybe you should double check the shape of your arrays. Incidentally, if your arrays are already numpy arrays, why are you trying to convert them to numpy array again? Commented Sep 21, 2016 at 9:34
  • Are you sure y_axis, y_bot and y_top have the same length ? Commented Sep 21, 2016 at 9:34
  • I edited the question Commented Sep 21, 2016 at 9:46
  • Yes they are of same length Commented Sep 21, 2016 at 9:47
  • Could you include some example arrays that trigger the issue ? Commented Sep 21, 2016 at 10:16

1 Answer 1

3

The following works fine for me:

import numpy as np
import matplotlib.pyplot as plt
x_axis = range(4)
y_axis = range(4)
y_bot = range(4)
y_top = range(4)
plt.errorbar(np.array(x_axis), np.array(y_axis), yerr=(np.array(y_bot), np.array(y_top)), linestyle='None', marker='^')

You way want to verify your arrays

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.