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

Skip to content

Commit a30e8e7

Browse files
committed
Remove support for non-1D errorbars.
1 parent 66bfc00 commit a30e8e7

File tree

3 files changed

+11
-26
lines changed

3 files changed

+11
-26
lines changed

doc/api/api_changes_3.3/removals.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ Arguments
221221
- `.MaxNLocator.set_params()` no longer accepts arbitrary keyword arguments.
222222
- `~.Axes.pie` no longer accepts and squeezes non-1D inputs; pass 1D input to
223223
the ``x`` argument.
224+
- Passing (n, 1)-shaped error arrays to `.Axes.errorbar()` is no longer
225+
supported; pass a 1D array instead.
224226

225227
rcParams
226228
~~~~~~~~

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3368,7 +3368,7 @@ def xywhere(xs, ys, mask):
33683368
ys = [thisy for thisy, b in zip(ys, mask) if b]
33693369
return xs, ys
33703370

3371-
def extract_err(err, data):
3371+
def extract_err(name, err, data):
33723372
"""
33733373
Private function to parse *err* and subtract/add it to *data*.
33743374
@@ -3380,20 +3380,9 @@ def extract_err(err, data):
33803380
iter(b)
33813381
except (TypeError, ValueError):
33823382
a = b = err # Symmetric error: 1D iterable.
3383-
# This could just be `np.ndim(a) > 1 and np.ndim(b) > 1`, except
3384-
# for the (undocumented, but tested) support for (n, 1) arrays.
3385-
a_sh = np.shape(a)
3386-
b_sh = np.shape(b)
3387-
if (len(a_sh) > 2 or (len(a_sh) == 2 and a_sh[1] != 1)
3388-
or len(b_sh) > 2 or (len(b_sh) == 2 and b_sh[1] != 1)):
3383+
if np.ndim(a) > 1 or np.ndim(b) > 1:
33893384
raise ValueError(
3390-
"err must be a scalar or a 1D or (2, n) array-like")
3391-
if len(a_sh) == 2 or len(b_sh) == 2:
3392-
cbook.warn_deprecated(
3393-
"3.1", message="Support for passing a (n, 1)-shaped error "
3394-
"array to errorbar() is deprecated since Matplotlib "
3395-
"%(since)s and will be removed %(removal)s; pass a 1D "
3396-
"array instead.")
3385+
f"{name}err must be a scalar or a 1D or (2, n) array-like")
33973386
# Using list comprehensions rather than arrays to preserve units.
33983387
for e in [a, b]:
33993388
if len(data) != len(e):
@@ -3405,7 +3394,7 @@ def extract_err(err, data):
34053394
return low, high
34063395

34073396
if xerr is not None:
3408-
left, right = extract_err(xerr, x)
3397+
left, right = extract_err('x', xerr, x)
34093398
# select points without upper/lower limits in x and
34103399
# draw normal errorbars for these points
34113400
noxlims = ~(xlolims | xuplims)
@@ -3454,7 +3443,7 @@ def extract_err(err, data):
34543443
**eb_cap_style))
34553444

34563445
if yerr is not None:
3457-
lower, upper = extract_err(yerr, y)
3446+
lower, upper = extract_err('y', yerr, y)
34583447
# select points without upper/lower limits in y and
34593448
# draw normal errorbars for these points
34603449
noylims = ~(lolims | uplims)

lib/matplotlib/tests/test_axes.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,9 +2855,7 @@ def test_errorbar():
28552855
# Now switch to a more OO interface to exercise more features.
28562856
fig, axs = plt.subplots(nrows=2, ncols=2, sharex=True)
28572857
ax = axs[0, 0]
2858-
# Try a Nx1 shaped error just to check
2859-
with pytest.warns(MatplotlibDeprecationWarning):
2860-
ax.errorbar(x, y, yerr=np.reshape(yerr, (len(y), 1)), fmt='o')
2858+
ax.errorbar(x, y, yerr=yerr, fmt='o')
28612859
ax.set_title('Vert. symmetric')
28622860

28632861
# With 4 subplots, reduce the number of axis ticks to avoid crowding.
@@ -4754,10 +4752,8 @@ def generate_errorbar_inputs():
47544752
[1, 1, 1, 1, 1],
47554753
[[1, 1, 1, 1, 1],
47564754
[1, 1, 1, 1, 1]],
4757-
[[1]] * 5,
47584755
np.ones(5),
47594756
np.ones((2, 5)),
4760-
np.ones((5, 1)),
47614757
None
47624758
])
47634759
xerr_cy = cycler('xerr', err_cycler)
@@ -4774,11 +4770,9 @@ def generate_errorbar_inputs():
47744770

47754771
@pytest.mark.parametrize('kwargs', generate_errorbar_inputs())
47764772
def test_errorbar_inputs_shotgun(kwargs):
4777-
# (n, 1)-shaped error deprecation already tested by test_errorbar.
4778-
with mpl.cbook._suppress_matplotlib_deprecation_warning():
4779-
ax = plt.gca()
4780-
eb = ax.errorbar(**kwargs)
4781-
eb.remove()
4773+
ax = plt.gca()
4774+
eb = ax.errorbar(**kwargs)
4775+
eb.remove()
47824776

47834777

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

0 commit comments

Comments
 (0)