diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 3796d9bbe508..cbc7cc0adf41 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -3562,6 +3562,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")
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: