Skip to content

Navigation Menu

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

Commit 11b8e4e

Browse filesBrowse files
authored
Merge pull request #30079 from rcomer/legend-iter
FIX: cast legend handles to list
2 parents 1c881a3 + b41edd0 commit 11b8e4e
Copy full SHA for 11b8e4e

File tree

2 files changed

+13
-0
lines changed
Filter options

2 files changed

+13
-0
lines changed

‎lib/matplotlib/legend.py

Copy file name to clipboardExpand all lines: lib/matplotlib/legend.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ def __init__(
459459
labels = [*reversed(labels)]
460460
handles = [*reversed(handles)]
461461

462+
handles = list(handles)
462463
if len(handles) < 2:
463464
ncols = 1
464465
self._ncols = ncols if ncols != 1 else ncol

‎lib/matplotlib/tests/test_legend.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_legend.py
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ def test_legend_ordereddict():
4242
loc='center left', bbox_to_anchor=(1, .5))
4343

4444

45+
def test_legend_generator():
46+
# smoketest that generator inputs work
47+
fig, ax = plt.subplots()
48+
ax.plot([0, 1])
49+
ax.plot([0, 2])
50+
51+
handles = (line for line in ax.get_lines())
52+
labels = (label for label in ['spam', 'eggs'])
53+
54+
ax.legend(handles, labels, loc='upper left')
55+
56+
4557
@image_comparison(['legend_auto1.png'], remove_text=True)
4658
def test_legend_auto1():
4759
"""Test automatic legend placement"""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.