Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a4e3694

Browse filesBrowse files
committed
FIX: fix passing empty lists to errorbar xerr/yerr
closes #5641
1 parent 5ccc604 commit a4e3694
Copy full SHA for a4e3694

File tree

Expand file treeCollapse file tree

2 files changed

+51
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+51
-8
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+10-7Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,7 +2879,7 @@ def xywhere(xs, ys, mask):
28792879

28802880
if xerr is not None:
28812881
if (iterable(xerr) and len(xerr) == 2 and
2882-
iterable(xerr[0]) and iterable(xerr[1])):
2882+
iterable(xerr[0]) and iterable(xerr[1])):
28832883
# using list comps rather than arrays to preserve units
28842884
left = [thisx - thiserr for (thisx, thiserr)
28852885
in cbook.safezip(x, xerr[0])]
@@ -2889,9 +2889,11 @@ def xywhere(xs, ys, mask):
28892889
# Check if xerr is scalar or symmetric. Asymmetric is handled
28902890
# above. This prevents Nx2 arrays from accidentally
28912891
# being accepted, when the user meant the 2xN transpose.
2892-
if not (len(xerr) == 1 or
2893-
(len(xerr) == len(x) and not (
2894-
iterable(xerr[0]) and len(xerr[0]) > 1))):
2892+
# special case for empty lists
2893+
if len(xerr) and not (len(xerr) == 1 or
2894+
(len(xerr) == len(x) and not (
2895+
iterable(xerr[0]) and
2896+
len(xerr[0]) > 1))):
28952897
raise ValueError("xerr must be a scalar, the same "
28962898
"dimensions as x, or 2xN.")
28972899
# using list comps rather than arrays to preserve units
@@ -2953,9 +2955,10 @@ def xywhere(xs, ys, mask):
29532955
in cbook.safezip(y, yerr[1])]
29542956
else:
29552957
# Check for scalar or symmetric, as in xerr.
2956-
if not (len(yerr) == 1 or
2957-
(len(yerr) == len(y) and not (
2958-
iterable(yerr[0]) and len(yerr[0]) > 1))):
2958+
if len(yerr) and not (len(yerr) == 1 or
2959+
(len(yerr) == len(y) and not (
2960+
iterable(yerr[0]) and
2961+
len(yerr[0]) > 1))):
29592962
raise ValueError("yerr must be a scalar, the same "
29602963
"dimensions as y, or 2xN.")
29612964
# using list comps rather than arrays to preserve units

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+41-1Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import six
55
from six.moves import xrange
6-
6+
from itertools import chain
77
import io
88

99
from nose.tools import assert_equal, assert_raises, assert_false, assert_true
@@ -13,6 +13,7 @@
1313
import numpy as np
1414
from numpy import ma
1515
from numpy import arange
16+
from cycler import cycler
1617

1718
import matplotlib
1819
from matplotlib.testing.decorators import image_comparison, cleanup
@@ -4093,6 +4094,42 @@ def test_violin_point_mass():
40934094
plt.violinplot(np.array([0, 0]))
40944095

40954096

4097+
def _eb_succes_helper(ax, x, y, xerr=None, yerr=None):
4098+
eb = ax.errorbar(x, y, xerr=xerr, yerr=yerr)
4099+
eb.remove()
4100+
4101+
4102+
@cleanup
4103+
def test_errorbar_inputs_shotgun():
4104+
base_xy = cycler('x', [np.arange(5)]) + cycler('y', [np.ones((5, ))])
4105+
err_cycler = cycler('err', [1,
4106+
[1, 1, 1, 1, 1],
4107+
[[1, 1, 1, 1, 1],
4108+
[1, 1, 1, 1, 1]],
4109+
np.ones(5),
4110+
np.ones((2, 5)),
4111+
None
4112+
])
4113+
xerr_cy = cycler('xerr', err_cycler)
4114+
yerr_cy = cycler('yerr', err_cycler)
4115+
4116+
empty = ((cycler('x', [[]]) + cycler('y', [[]])) *
4117+
cycler('xerr', [[], None]) * cycler('yerr', [[], None]))
4118+
xerr_only = base_xy * xerr_cy
4119+
yerr_only = base_xy * yerr_cy
4120+
both_err = base_xy * yerr_cy * xerr_cy
4121+
4122+
test_cyclers = xerr_only, yerr_only, both_err, empty
4123+
4124+
ax = plt.gca()
4125+
# should do this as a generative test, but @cleanup seems to break that
4126+
# for p in chain(*test_cyclers):
4127+
# yield (_eb_succes_helper, ax) + tuple(p.get(k, None) for
4128+
# k in ['x', 'y', 'xerr', 'yerr'])
4129+
for p in chain(*test_cyclers):
4130+
_eb_succes_helper(ax, **p)
4131+
4132+
40964133
@cleanup
40974134
def test_remove_shared_axes():
40984135

@@ -4137,6 +4174,9 @@ def _helper_y(ax):
41374174
ax.set_xlim(0, 5)
41384175
assert assert_array_equal(ax_lst[0][1].get_xlim(), orig_xlim)
41394176

4177+
4178+
4179+
41404180
if __name__ == '__main__':
41414181
import nose
41424182
import sys

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.