1

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: "yerr must be a scalar, the same dimensions as y, or 2xN."

But Y.shape == Yerr.shape is True.

I'm running on 64 bit Windows 7 with Spyder 2.3.8 and Python 3.5.1. Matplotlib is up to date. I've installed Visual C++ Redistributable for Visual Studio 2015.

Any ideas?

Edit: Some data.

X=numpy.array([1,2,3])
Y=numpy.array([[1,5,2],[3,6,4],[9,3,7]])
Yerr=numpy.ones_like(Y)
2
  • include some code that generates example data that triggers this issue Commented Aug 8, 2016 at 23:32
  • Hmmm... the error message does not agree with the docstring, which says *xerr*/*yerr*: [ scalar | N, Nx1, or 2xN array-like ]. Commented Aug 9, 2016 at 2:07

2 Answers 2

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)
Sign up to request clarification or add additional context in comments.

Comments

1

Hmmm....

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

if len(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) > 1
2 T len(yerr) == len(y)
3 T iterable(yerr[0])
4 T len(yerr[0]) > 1
5 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.

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.