Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #4984 #4985

Merged
merged 1 commit into from Aug 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/matplotlib/axes/_axes.py
Expand Up @@ -2824,6 +2824,14 @@ def xywhere(xs, ys, mask):
right = [thisx + thiserr for (thisx, thiserr)
in cbook.safezip(x, xerr[1])]
else:
# Check if xerr is scalar or symmetric. Asymmetric is handled
# above. This prevents Nx2 arrays from accidentally
# being accepted, when the user meant the 2xN transpose.
if not (len(xerr) == 1 or
(len(xerr) == len(x) and not (
iterable(xerr[0]) and len(xerr[0]) > 1))):
raise ValueError("xerr must be a scalar, the same "
"dimensions as x, or 2xN.")
# using list comps rather than arrays to preserve units
left = [thisx - thiserr for (thisx, thiserr)
in cbook.safezip(x, xerr)]
Expand Down Expand Up @@ -2882,6 +2890,12 @@ def xywhere(xs, ys, mask):
upper = [thisy + thiserr for (thisy, thiserr)
in cbook.safezip(y, yerr[1])]
else:
# Check for scalar or symmetric, as in xerr.
if not (len(yerr) == 1 or
(len(yerr) == len(y) and not (
iterable(yerr[0]) and len(yerr[0]) > 1))):
raise ValueError("yerr must be a scalar, the same "
"dimensions as y, or 2xN.")
# using list comps rather than arrays to preserve units
lower = [thisy - thiserr for (thisy, thiserr)
in cbook.safezip(y, yerr)]
Expand Down
18 changes: 17 additions & 1 deletion lib/matplotlib/tests/test_axes.py
Expand Up @@ -2038,7 +2038,8 @@ def test_errorbar():
# Now switch to a more OO interface to exercise more features.
fig, axs = plt.subplots(nrows=2, ncols=2, sharex=True)
ax = axs[0, 0]
ax.errorbar(x, y, yerr=yerr, fmt='o')
# Try a Nx1 shaped error just to check
ax.errorbar(x, y, yerr=np.reshape(yerr, (len(y), 1)), fmt='o')
ax.set_title('Vert. symmetric')

# With 4 subplots, reduce the number of axis ticks to avoid crowding.
Expand All @@ -2064,6 +2065,21 @@ def test_errorbar():

fig.suptitle('Variable errorbars')

@cleanup
def test_errorbar_shape():
fig = plt.figure()
ax = fig.gca()

x = np.arange(0.1, 4, 0.5)
y = np.exp(-x)
yerr1 = 0.1 + 0.2*np.sqrt(x)
yerr = np.vstack((yerr1, 2*yerr1)).T
xerr = 0.1 + yerr

assert_raises(ValueError, ax.errorbar, x, y, yerr=yerr, fmt='o')
assert_raises(ValueError, ax.errorbar, x, y, xerr=xerr, fmt='o')
assert_raises(ValueError, ax.errorbar, x, y, yerr=yerr, xerr=xerr, fmt='o')


@image_comparison(baseline_images=['errorbar_limits'])
def test_errorbar_limits():
Expand Down