Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix the error- TypeError: 'float' object is not iterable #22710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 5, 2022
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
7 changes: 5 additions & 2 deletions lib/matplotlib/axis.py
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
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)


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