8000 TST: add smoketest for ordereddict legend handles · matplotlib/matplotlib@3d65ca1 · GitHub
[go: up one dir, main page]

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

Commit 3d65ca1

Browse files
committed
TST: add smoketest for ordereddict legend handles
1 parent ba834ce commit 3d65ca1

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/matplotlib/legend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ def __init__(self, parent, handles, labels,
599599
else:
600600
_lab.append(label)
601601
_hand.append(handle)
602-
label, handle = _lab, _hand
602+
labels, handles = _lab, _hand
603603

604604
handles = list(handles)
605605
if len(handles) < 2:

lib/matplotlib/tests/test_legend.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from unittest import mock
66
except ImportError:
77
import mock
8+
import collections
89
import numpy as np
910
import pytest
1011

@@ -53,6 +54,23 @@ def test_legend_kwdocstrings():
5354
assert stleg == stfig
5455

5556

57+
def test_legend_ordereddict():
58+
# smoketest that ordereddict inputs work...
59+
60+
X = np.random.randn(10)
61+
Y = np.random.randn(10)
62+
labels = ['a'] * 5 + ['b'] * 5
63+
colors = ['r'] * 5 + ['g'] * 5
64+
65+
fig, ax = plt.subplots()
66+
for x, y, label, color in zip(X, Y, labels, colors):
67+
ax.scatter(x, y, label=label, c=color)
68+
69+
handles, labels = ax.get_legend_handles_labels()
70+
legend = collections.OrderedDict(zip(labels, handles))
71+
ax.legend(legend.values(), legend.keys(), loc=6, bbox_to_anchor=(1, .5))
72+
73+
5674
@image_comparison(baseline_images=['legend_auto1'], remove_text=True)
5775
def test_legend_auto1():
5876
'Test automatic legend placement'

0 commit comments

Comments
 (0)
0