diff --git a/doc/api/next_api_changes/2019-01-18-AL.rst b/doc/api/next_api_changes/2019-01-18-AL.rst new file mode 100644 index 000000000000..ee8cdf93a021 --- /dev/null +++ b/doc/api/next_api_changes/2019-01-18-AL.rst @@ -0,0 +1,6 @@ +Deprecations +```````````` + +Support for passing (n, 1)-shaped error arrays to errorbar(), which was not +documented and did not work for ``n = 2``, is deprecated (pass a 1D array +instead). diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index a3635a7920fc..940b21b1816b 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3199,6 +3199,12 @@ def extract_err(err, data): or len(b_sh) > 2 or (len(b_sh) == 2 and b_sh[1] != 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.") # Using list comprehensions rather than arrays to preserve units. low = [v - e for v, e in cbook.safezip(data, a)] high = [v + e for v, e in cbook.safezip(data, b)] diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 1e549feda3d0..1b223c5c5b17 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -2899,7 +2899,8 @@ def test_errorbar(): fig, axs = plt.subplots(nrows=2, ncols=2, sharex=True) ax = axs[0, 0] # Try a Nx1 shaped error just to check - ax.errorbar(x, y, yerr=np.reshape(yerr, (len(y), 1)), fmt='o') + with pytest.warns(MatplotlibDeprecationWarning): + 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. @@ -5248,9 +5249,12 @@ def generate_errorbar_inputs(): @pytest.mark.parametrize('kwargs', generate_errorbar_inputs()) def test_errorbar_inputs_shotgun(kwargs): - ax = plt.gca() - eb = ax.errorbar(**kwargs) - eb.remove() + with warnings.catch_warnings(): + # (n, 1)-shaped error deprecation already tested by test_errorbar. + warnings.simplefilter("ignore", MatplotlibDeprecationWarning) + ax = plt.gca() + eb = ax.errorbar(**kwargs) + eb.remove() @image_comparison(baseline_images=["dash_offset"], remove_text=True)