Skip to content

Commit 60412ad

Browse files
timhoffmmeeseeksmachine
authored andcommitted
Backport PR matplotlib#31758: Fix invalid format string in set_xticklabels error message.
1 parent dbc3991 commit 60412ad

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

lib/matplotlib/axis.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,11 +2147,10 @@ def set_ticklabels(self, labels, *, minor=False, fontdict=None, **kwargs):
21472147
labels = [t.get_text() if hasattr(t, 'get_text') else t
21482148
for t in labels]
21492149
except TypeError:
2150-
raise TypeError(f"{labels:=} must be a sequence") from None
2150+
raise TypeError(f"{labels=!r} must be a sequence") from None
21512151
locator = (self.get_minor_locator() if minor
21522152
else self.get_major_locator())
21532153
if not labels:
2154-
# eg labels=[]:
21552154
formatter = mticker.NullFormatter()
21562155
elif (isinstance(locator, mticker.FixedLocator) or
21572156
(hasattr(locator, 'base') and

lib/matplotlib/tests/test_axes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6988,6 +6988,8 @@ def test_xticks_bad_args():
69886988
ax = plt.figure().add_subplot()
69896989
with pytest.raises(TypeError, match='must be a sequence'):
69906990
ax.set_xticks([2, 9], 3.1)
6991+
with pytest.raises(TypeError, match='must be a sequence'):
6992+
ax.set_xticks([2, 9], ax)
69916993
with pytest.raises(ValueError, match='must be 1D'):
69926994
plt.xticks(np.arange(4).reshape((-1, 1)))
69936995
with pytest.raises(ValueError, match='must be 1D'):

0 commit comments

Comments
 (0)