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

Skip to content

Deprecate support for (n, 1)-shaped error arrays in errorbar(). #13209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/2019-01-18-AL.rst
Original file line number Diff line number Diff line change
@@ -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).
6 changes: 6 additions & 0 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
12 changes: 8 additions & 4 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down