Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_category.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Catch all for categorical functions"""
import warnings

import pytest
import numpy as np

Expand Down Expand Up @@ -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")