diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index ab6cc4dd5993..289239e5417f 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -3578,6 +3578,8 @@ def _validate_converted_limits(self, limit, convert): """ if limit is not None: converted_limit = convert(limit) + if isinstance(converted_limit, np.ndarray): + converted_limit = converted_limit.squeeze() if (isinstance(converted_limit, Real) and not np.isfinite(converted_limit)): raise ValueError("Axis limits cannot be NaN or Inf") diff --git a/lib/matplotlib/tests/test_category.py b/lib/matplotlib/tests/test_category.py index 87dece6346f7..fd4aec88b574 100644 --- a/lib/matplotlib/tests/test_category.py +++ b/lib/matplotlib/tests/test_category.py @@ -1,4 +1,6 @@ """Catch all for categorical functions""" +import warnings + import pytest import numpy as np @@ -309,3 +311,13 @@ def test_hist(): n, bins, patches = ax.hist(['a', 'b', 'a', 'c', 'ff']) assert n.shape == (10,) np.testing.assert_allclose(n, [2., 0., 0., 1., 0., 0., 1., 0., 0., 1.]) + + +def test_set_lim(): + # Numpy 1.25 deprecated casting [2.] to float, catch_warnings added to error + # with numpy 1.25 and prior to the change from gh-26597 + # can be removed once the minimum numpy version has expired the warning + f, ax = plt.subplots() + ax.plot(["a", "b", "c", "d"], [1, 2, 3, 4]) + with warnings.catch_warnings(): + ax.set_xlim("b", "c")