@@ -12,14 +12,14 @@ What to be displayed
12
12
====================
13
13
14
14
The legend command has a following call signature::
15
-
15
+
16
16
legend(*args, **kwargs)
17
-
17
+
18
18
If len(args) is 2, the first argument should be a list of artist to be
19
19
labeled, and the second argument should a list of string labels. If
20
20
len(args) is 0, it automatically generate the legend from label
21
21
properties of the child artists by calling
22
- :meth: `~matplotlib.axes.Axes.get_legend_handles_labels ` method.
22
+ :meth: `~matplotlib.axes.Axes.get_legend_handles_labels ` method.
23
23
For example, *ax.legend() * is equivalent to::
24
24
25
25
handles, labels = ax.get_legend_handles_labels()
@@ -44,7 +44,7 @@ used as text labels. If label attribute is empty string or starts with
44
44
* :class: `~matplotlib.patches.Patch `
45
45
* :class: `~matplotlib.collections.LineCollection `
46
46
* :class: `~matplotlib.collections.RegularPolyCollection `
47
-
47
+
48
48
Unfortunately, there is no easy workaround when you need legend for
49
49
an artist not in the above list (You may use one of the supported
50
50
artist as a proxy. See below), or customize it beyond what is
@@ -84,28 +84,28 @@ feeding them to legend call.::
84
84
p1, = ax.plot([1,2,3], label="line 1")
85
85
p2, = ax.plot([3,2,1], label="line 2")
86
86
p3, = ax.plot([2,3,1], label="line 3")
87
-
87
+
88
88
handles, labels = ax.get_legend_handles_labels()
89
89
90
90
# reverse the order
91
91
ax.legend(handles[::-1], labels[::-1])
92
-
92
+
93
93
# or sort them by labels
94
94
import operator
95
95
hl = sorted(zip(handles, labels),
96
96
key=operator.itemgetter(1))
97
97
handles2, labels2 = zip(*hl)
98
-
98
+
99
99
ax.legend(handles2, labels2)
100
100
101
101
102
102
Using Proxy Artist
103
103
------------------
104
104
105
- When you want to display legend for an artist not supported by the
106
- matplotlib, you may use other supported artist as a proxy. For
107
- example, you may creates an proxy artist without adding it to the axes
108
- (so the proxy artist will not be drawn in the main axes) and feet it
105
+ When you want to display legend for an artist not supported by
106
+ matplotlib, you may use another artist as a proxy. For
107
+ example, you may create a proxy artist without adding it to the axes
108
+ (so the proxy artist will not be drawn in the main axes) and feed it
109
109
to the legend function.::
110
110
111
111
p = Rectangle((0, 0), 1, 1, fc="r")
0 commit comments