Skip to content

Commit

Permalink
Remove support for non-1D errorbars.
Browse files Browse the repository at this point in the history
  • Loading branch information
QuLogic committed Apr 25, 2020
1 parent 66bfc00 commit a30e8e7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 26 deletions.
2 changes: 2 additions & 0 deletions doc/api/api_changes_3.3/removals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ Arguments
- `.MaxNLocator.set_params()` no longer accepts arbitrary keyword arguments.
- `~.Axes.pie` no longer accepts and squeezes non-1D inputs; pass 1D input to
the ``x`` argument.
- Passing (n, 1)-shaped error arrays to `.Axes.errorbar()` is no longer
supported; pass a 1D array instead.

rcParams
~~~~~~~~
Expand Down
21 changes: 5 additions & 16 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3368,7 +3368,7 @@ def xywhere(xs, ys, mask):
ys = [thisy for thisy, b in zip(ys, mask) if b]
return xs, ys

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

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

if yerr is not None:
lower, upper = extract_err(yerr, y)
lower, upper = extract_err('y', yerr, y)
# select points without upper/lower limits in y and
# draw normal errorbars for these points
noylims = ~(lolims | uplims)
Expand Down
14 changes: 4 additions & 10 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2855,9 +2855,7 @@ 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]
# Try a Nx1 shaped error just to check
with pytest.warns(MatplotlibDeprecationWarning):
ax.errorbar(x, y, yerr=np.reshape(yerr, (len(y), 1)), fmt='o')
ax.errorbar(x, y, yerr=yerr, fmt='o')
ax.set_title('Vert. symmetric')

# With 4 subplots, reduce the number of axis ticks to avoid crowding.
Expand Down Expand Up @@ -4754,10 +4752,8 @@ def generate_errorbar_inputs():
[1, 1, 1, 1, 1],
[[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]],
[[1]] * 5,
np.ones(5),
np.ones((2, 5)),
np.ones((5, 1)),
None
])
xerr_cy = cycler('xerr', err_cycler)
Expand All @@ -4774,11 +4770,9 @@ def generate_errorbar_inputs():

@pytest.mark.parametrize('kwargs', generate_errorbar_inputs())
def test_errorbar_inputs_shotgun(kwargs):
# (n, 1)-shaped error deprecation already tested by test_errorbar.
with mpl.cbook._suppress_matplotlib_deprecation_warning():
ax = plt.gca()
eb = ax.errorbar(**kwargs)
eb.remove()
ax = plt.gca()
eb = ax.errorbar(**kwargs)
eb.remove()


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

0 comments on commit a30e8e7

Please sign in to comment.