Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Backport PR #30079 on branch v3.10.x (FIX: cast legend handles to list) #30081

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
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
1 change: 1 addition & 0 deletions 1 lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def __init__(
labels = [*reversed(labels)]
handles = [*reversed(handles)]

handles = list(handles)
if len(handles) < 2:
ncols = 1
self._ncols = ncols if ncols != 1 else ncol
Expand Down
12 changes: 12 additions & 0 deletions 12 lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ def test_legend_ordereddict():
loc='center left', bbox_to_anchor=(1, .5))


def test_legend_generator():
# smoketest that generator inputs work
fig, ax = plt.subplots()
ax.plot([0, 1])
ax.plot([0, 2])

handles = (line for line in ax.get_lines())
labels = (label for label in ['spam', 'eggs'])

ax.legend(handles, labels, loc='upper left')


@image_comparison(['legend_auto1.png'], remove_text=True)
def test_legend_auto1():
"""Test automatic legend placement"""
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.