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

Skip to content

Commit c37cf41

Browse files
authored
Merge pull request #26654 from meeseeksmachine/auto-backport-of-pr-26597-on-v3.8.x
Backport PR #26597 on branch v3.8.x (Squeeze post-converted values when validating limits)
2 parents 0017807 + 26a9c79 commit c37cf41

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3578,6 +3578,8 @@ def _validate_converted_limits(self, limit, convert):
35783578
"""
35793579
if limit is not None:
35803580
converted_limit = convert(limit)
3581+
if isinstance(converted_limit, np.ndarray):
3582+
converted_limit = converted_limit.squeeze()
35813583
if (isinstance(converted_limit, Real)
35823584
and not np.isfinite(converted_limit)):
35833585
raise ValueError("Axis limits cannot be NaN or Inf")

lib/matplotlib/tests/test_category.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Catch all for categorical functions"""
2+
import warnings
3+
24
import pytest
35
import numpy as np
46

@@ -309,3 +311,13 @@ def test_hist():
309311
n, bins, patches = ax.hist(['a', 'b', 'a', 'c', 'ff'])
310312
assert n.shape == (10,)
311313
np.testing.assert_allclose(n, [2., 0., 0., 1., 0., 0., 1., 0., 0., 1.])
314+
315+
316+
def test_set_lim():
317+
# Numpy 1.25 deprecated casting [2.] to float, catch_warnings added to error
318+
# with numpy 1.25 and prior to the change from gh-26597
319+
# can be removed once the minimum numpy version has expired the warning
320+
f, ax = plt.subplots()
321+
ax.plot(["a", "b", "c", "d"], [1, 2, 3, 4])
322+
with warnings.catch_warnings():
323+
ax.set_xlim("b", "c")

0 commit comments

Comments
 (0)