8000 FIX: cast legend handles to list · matplotlib/matplotlib@b41edd0 · GitHub
[go: up one dir, main page]

Skip to content

Commit b41edd0

Browse files
committed
FIX: cast legend handles to list
1 parent 1c881a3 commit b41edd0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/matplotlib/legend.py

Lines 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

Lines 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