FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix the error- TypeError: 'float' object is not iterable by krishjainx · Pull Request #22710 · matplotlib/matplotlib · GitHub

Repository navigation

7 changes: 5 additions & 2 deletions lib/matplotlib/axis.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1825,8 +1825,11 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
For each tick, includes ``tick.label1`` if it is visible, then
``tick.label2`` if it is visible, in that order.
"""
ticklabels = [t.get_text() if hasattr(t, 'get_text') else t
for t in ticklabels]
try:
ticklabels = [t.get_text() if hasattr(t, 'get_text') else t
for t in ticklabels]
except TypeError:
raise TypeError(f"{ticklabels:=} must be a sequence") from None
locator = (self.get_minor_locator() if minor
else self.get_major_locator())
if isinstance(locator, mticker.FixedLocator):
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -5388,6 +5388,15 @@ def test_set_ticks_with_labels(fig_test, fig_ref):
ax.set_yticks([2, 4], ['A', 'B'], minor=True)


def test_set_noniterable_ticklabels():
# Ensure a useful TypeError message is raised
# when given a non-iterable ticklabels argument
# Pull request #22710
with pytest.raises(TypeError, match='must be a sequence'):
fig, ax = plt.subplots(2)
ax[1].set_xticks([2, 9], 3.1)
Comment thread
krishjainx marked this conversation as resolved.


def test_subsampled_ticklabels():
# test issue 11937
fig, ax = plt.subplots()
Expand Down

Back | FazBrowse Home | New Git URL