Skip to content

Commit 89021bf

Browse files
committed
modified pyplot.figlegend
1 parent fbd5005 commit 89021bf

File tree

6 files changed

+128
-68
lines changed

6 files changed

+128
-68
lines changed

lib/matplotlib/figure.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,13 +1075,23 @@ def get_axes(self):
10751075

10761076
def legend(self, *args, **kwargs):
10771077
"""
1078-
Place a legend in the figure. Labels are a sequence of
1079-
strings, handles is a sequence of
1080-
:class:`~matplotlib.lines.Line2D` or
1081-
:class:`~matplotlib.patches.Patch` instances, and loc can be a
1082-
string or an integer specifying the legend location
1078+
Place a legend in the figure.
1079+
1080+
*labels*
1081+
a sequence of strings
1082+
1083+
*handles*
1084+
a sequence of :class:`~matplotlib.lines.Line2D` or
1085+
:class:`~matplotlib.patches.Patch` instances
1086+
1087+
*loc*
1088+
can be a string or an integer specifying the legend
1089+
location
10831090
1084-
USAGE::
1091+
A :class:`matplotlib.legend.Legend` instance is returned.
1092+
1093+
1094+
Example::
10851095
10861096
To make a legend from existing artists on every axes::
10871097
@@ -1184,12 +1194,18 @@ def legend(self, *args, **kwargs):
11841194
return None
11851195

11861196
elif len(args) == 2:
1197+
# LINES, LABELS
11871198
handles, labels = args
11881199

1200+
elif len(args) == 3:
1201+
# LINES, LABELS, LOC
1202+
handles, labels, loc = args
1203+
kwargs['loc'] = loc
1204+
11891205
else:
11901206
raise TypeError('Invalid arguments to legend')
11911207

1192-
l = Legend(self, handles, labels, *args, **kwargs)
1208+
l = Legend(self, handles, labels, **kwargs)
11931209
self.legends.append(l)
11941210
l._remove_method = lambda h: self.legends.remove(h)
11951211
return l

lib/matplotlib/pyplot.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def figimage(*args, **kwargs):
627627
return ret
628628

629629

630-
def figlegend(handles, labels, loc, **kwargs):
630+
def figlegend(*args, **kwargs):
631631
"""
632632
Place a legend in the figure.
633633
@@ -646,6 +646,12 @@ def figlegend(handles, labels, loc, **kwargs):
646646
647647
Example::
648648
649+
To make a legend from existing artists on every axes::
650+
651+
legend()
652+
653+
To make a legend for a list of lines and labels::
654+
649655
figlegend( (line1, line2, line3),
650656
('label1', 'label2', 'label3'),
651657
'upper right' )
@@ -655,7 +661,7 @@ def figlegend(handles, labels, loc, **kwargs):
655661
:func:`~matplotlib.pyplot.legend`
656662
657663
"""
658-
l = gcf().legend(handles, labels, loc, **kwargs)
664+
l = gcf().legend(*args, **kwargs)
659665
draw_if_interactive()
660666
return l
661667

Binary file not shown.

0 commit comments

Comments
 (0)