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

Skip to content

Commit d966e54

Browse files
authored
Merge pull request #13501 from meeseeksmachine/auto-backport-of-pr-13209-on-v3.1.x
Backport PR #13209 on branch v3.1.x (Deprecate support for (n, 1)-shaped error arrays in errorbar().)
2 parents fb85c16 + 5dc0474 commit d966e54

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed
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
@@ -3309,6 +3309,12 @@ def extract_err(err, data):
33093309
or len(b_sh) > 2 or (len(b_sh) == 2 and b_sh[1] != 1)):
33103310
raise ValueError(
33113311
"err must be a scalar or a 1D or (2, n) array-like")
3312+
if len(a_sh) == 2 or len(b_sh) == 2:
3313+
cbook.warn_deprecated(
3314+
"3.1", message="Support for passing a (n, 1)-shaped error "
3315+
"array to errorbar() is deprecated since Matplotlib "
3316+
"%(since)s and will be removed %(removal)s; pass a 1D "
3317+
"array instead.")
33123318
# Using list comprehensions rather than arrays to preserve units.
33133319
for e in [a, b]:
33143320
if len(data) != len(e):

lib/matplotlib/tests/test_axes.py

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

28472848
# With 4 subplots, reduce the number of axis ticks to avoid crowding.
@@ -5219,9 +5220,12 @@ def generate_errorbar_inputs():
52195220

52205221
@pytest.mark.parametrize('kwargs', generate_errorbar_inputs())
52215222
def test_errorbar_inputs_shotgun(kwargs):
5222-
ax = plt.gca()
5223-
eb = ax.errorbar(**kwargs)
5224-
eb.remove()
5223+
with warnings.catch_warnings():
5224+
# (n, 1)-shaped error deprecation already tested by test_errorbar.
5225+
warnings.simplefilter("ignore", MatplotlibDeprecationWarning)
5226+
ax = plt.gca()
5227+
eb = ax.errorbar(**kwargs)
5228+
eb.remove()
52255229

52265230

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

0 commit comments

Comments
 (0)