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

Skip to content

Commit 815ab8a

Browse files
QuLogicmeeseeksmachine
authored andcommitted
Backport PR #26597: Squeeze post-converted values when validating limits
1 parent 3c98167 commit 815ab8a

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
@@ -3565,6 +3565,8 @@ def _validate_converted_limits(self, limit, convert):
35653565
"""
35663566
if limit is not None:
35673567
converted_limit = convert(limit)
3568+
if isinstance(converted_limit, np.ndarray):
3569+
converted_limit = converted_limit.squeeze()
35683570
if (isinstance(converted_limit, Real)
35693571
and not np.isfinite(converted_limit)):
35703572
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)