Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4fc30a1

Browse files
committed
Deprecate support for (n, 1)-shaped error arrays in errorbar().
errorbar() documents that it supports the following shapes for error arrays: - scalar: Symmetric +/- values for all data points. - shape(N,): Symmetric +/-values for each data point. - shape(2,N): Separate - and + values for each bar. First row contains the lower errors, the second row contains the upper errors. - *None*: No errorbar. Actually it also supports (N, 1)-shaped arrays (treating them as shape (N,)), but this support is broken for N=2 *at least* since Matplotlib 1.5: N = 2; errorbar(range(N), range(N), np.arange(N).reshape((N, 1))) ... ValueError: In safezip, len(args[0])=2 but len(args[1])=1 (This works for other values of N.) Instead of further maintaining code to handle that case, just deprecate it (no one has apparently noticed the N=2 bug, suggesting that this (mis)feature is not much used anyways).
1 parent 7f4b044 commit 4fc30a1

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Deprecations
2+
````````````
3+
4+
Support for passing (n, 1)-shaped error arrays to errorbar(), which was not
5+
documented and did not work for ``n = 2``, is deprecated (pass a 1D array
6+
instead).

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3199,6 +3199,12 @@ def extract_err(err, data):
31993199
or len(b_sh) > 2 or (len(b_sh) == 2 and b_sh[1] != 1)):
32003200
raise ValueError(
32013201
"err must be a scalar or a 1D or (2, n) array-like")
3202+
if len(a_sh) == 2 or len(b_sh) == 2:
3203+
cbook.warn_deprecated(
3204+
"3.1", message="Support for passing a (n, 1)-shaped error "
3205+
"array to errorbar() is deprecated since Matplotlib "
3206+
"%(since)s and will be removed %(removal)s; pass a 1D "
3207+
"array instead.")
32023208
# Using list comprehensions rather than arrays to preserve units.
32033209
low = [v - e for v, e in cbook.safezip(data, a)]
32043210
high = [v + e for v, e in cbook.safezip(data, b)]

lib/matplotlib/tests/test_axes.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,7 +2899,8 @@ def test_errorbar():
28992899
fig, axs = plt.subplots(nrows=2, ncols=2, sharex=True)
29002900
ax = axs[0, 0]
29012901
# Try a Nx1 shaped error just to check
2902-
ax.errorbar(x, y, yerr=np.reshape(yerr, (len(y), 1)), fmt='o')
2902+
with pytest.warns(MatplotlibDeprecationWarning):
2903+
ax.errorbar(x, y, yerr=np.reshape(yerr, (len(y), 1)), fmt='o')
29032904
ax.set_title('Vert. symmetric')
29042905

29052906
# With 4 subplots, reduce the number of axis ticks to avoid crowding.
@@ -5248,9 +5249,12 @@ def generate_errorbar_inputs():
52485249

52495250
@pytest.mark.parametrize('kwargs', generate_errorbar_inputs())
52505251
def test_errorbar_inputs_shotgun(kwargs):
5251-
ax = plt.gca()
5252-
eb = ax.errorbar(**kwargs)
5253-
eb.remove()
5252+
with warnings.catch_warnings():
5253+
# (n, 1)-shaped error deprecation already tested by test_errorbar.
5254+
warnings.simplefilter("ignore", MatplotlibDeprecationWarning)
5255+
ax = plt.gca()
5256+
eb = ax.errorbar(**kwargs)
5257+
eb.remove()
52545258

52555259

52565260
@image_comparison(baseline_images=["dash_offset"], remove_text=True)

0 commit comments

Comments
 (0)