blackmamba
blackmamba

Reputation: 2002

ValueError: too many values to unpack matplotlib errorbar

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.

Upvotes: 0

Views: 4376

Answers (1)

Pascal Delange
Pascal Delange

Reputation: 526

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

Upvotes: 3

Related Questions