Skip to content Skip to sidebar Skip to footer

Matplotlib.pyplot.errorbar Is Throwing An Error It Shouldn't?

I'm trying to make an errorbar plot with my data. X is a 9 element ndarray. Y and Yerr are 9x5 ndarrays. When I call: matplotlib.pyplot.errorbar(X, Y, Yerr) I get a ValueError: 'y

Solution 1:

Maybe by "dimension of y" the docs actually meant 1xN...

Anyway, this could work:

for y, yerr in zip(Y, Yerr):
    matplotlib.pyplot.errorbar(X, y, yerr)

Solution 2:

Hmmm....

By studying lines 2962-2965 of the module that raises the error we find

iflen(yerr) > 1 and not ((len(yerr) == len(y) and not (iterable(yerr[0]) and len(yerr[0]) > 1)))

From the data

1 T len(yerr) > 12 T len(yerr) == len(y)
3 T iterable(yerr[0])4 T len(yerr[0]) > 15 T 1 and not(2 and not (3 and 4)

However, this will not be triggered if the following test is not passed:

if (iterable(yerr) and len(yerr) == 2 and
                iterable(yerr[0]) and iterable(yerr[1])):
....

And it is not triggered, because len(yerr) = 3

Everything seems to check out, except for the dimensionality. This works:

X = numpy.tile([1,2,3],3)
Y = numpy.array([1,5,2,3,6,4,9,3,7])
Yerr = numpy.ones_like(Y)

I am not sure what causes the error. The "l0, = " assignment also seems a little quirky.

Post a Comment for "Matplotlib.pyplot.errorbar Is Throwing An Error It Shouldn't?"