Skip to content

Misleading error message for matplotlib.pyplot.errorbar() #6933

Closed
@dlmccaffrey

Description

@dlmccaffrey

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

I ran into an interesting issue with the matplotlib.pyplot.errorbar() function. I didn't read the documentation thoroughly and assumed that I would be able to use 2D arrays as inputs like with plot(). So, when I used the following code:

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

I get the following error:

File "\lib\site-packages\matplotlib\axes\_axes.py", line 2964, in errorbar
    raise ValueError("yerr must be a scalar, the same "

ValueError: yerr must be a scalar, the same dimensions as y, or 2xN.

I suggest changing the message to something like "yerr must be [ scalar | N, Nx1, or 2xN array-like ]" to match the documentation. Same for xerr.

Consequently, is there a reason that errorbar() needs flattened data when plot() doesn't? It might be worth changing. I ran into the issue when I was using plot() to plot trendlines for multiple datasets and wanted to put errorbars on the data. Flattening the trendlines doesn't work well because it connects the end of one trendline to the beginning of the next.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions