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

Skip to content

Commit ba834ce

Browse files
committed
FIX: allow OrderedDict legend handles and labels
1 parent 0db0992 commit ba834ce

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/matplotlib/legend.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,17 @@ def __init__(self, parent, handles, labels,
589589
setattr(self, name, value)
590590
del locals_view
591591
# trim handles and labels if illegal label...
592-
for label, handle in zip(labels[:], handles[:]):
593-
if (isinstance(label, six.string_types) and
594-
label.startswith('_')):
595-
warnings.warn('The handle {!r} has a label of {!r} which '
596-
'cannot be automatically added to the '
597-
'legend.'.format(handle, label))
598-
labels.remove(label)
599-
handles.remove(handle)
592+
_lab, _hand = [], []
593+
for label, handle in zip(labels, handles):
594+
if (isinstance(label, six.string_types) and
595+
label.startswith('_')):
596+
warnings.warn('The handle {!r} has a label of {!r} which '
597+
'cannot be automatically added to the '
598+
'legend.'.format(handle, label))
599+
else:
600+
_lab.append(label)
601+
_hand.append(handle)
602+
label, handle = _lab, _hand
600603

601604
handles = list(handles)
602605
if len(handles) < 2:

0 commit comments

Comments
 (0)