@@ -42,23 +42,27 @@ handles and their associated labels. This functionality is equivalent to::
42
42
43
43
The :meth: `~matplotlib.axes.Axes.get_legend_handles_labels ` function returns
44
44
a list of handles/artists which exist on the Axes which can be used to
45
- generate entries for the resulting legend.
45
+ generate entries for the resulting legend - it is worth noting however that
46
+ not all artists can be added to a legend, at which point a "proxy" will have
47
+ to be created (see :ref: `proxy_legend_handles ` for further details).
46
48
47
49
For full control of what is being added to the legend, it is common to pass
48
50
the appropriate handles directly to :func: `legend `::
49
51
50
- line2 , = plt.plot([1,2,3], label='Line 2')
51
- line1 , = plt.plot([3,2,1], label='Line 1')
52
- plt.legend(handles=[line1, line2 ])
52
+ line_up , = plt.plot([1,2,3], label='Line 2')
53
+ line_down , = plt.plot([3,2,1], label='Line 1')
54
+ plt.legend(handles=[line_up, line_down ])
53
55
54
56
In some cases, it is not possible to set the label of the handle, so it is
55
57
possible to pass through the list of labels to :func: `legend `::
56
58
57
- line2 , = plt.plot([1,2,3], label='Line 2')
58
- line1 , = plt.plot([3,2,1], label='Line 1')
59
- plt.legend([line1, line2 ], ['Custom label for line 1 ', 'Line 1 '])
59
+ line_up , = plt.plot([1,2,3], label='Line 2')
60
+ line_down , = plt.plot([3,2,1], label='Line 1')
61
+ plt.legend([line_up, line_down ], ['Line Up ', 'Line Down '])
60
62
61
63
64
+ .. _proxy_legend_handles :
65
+
62
66
Creating artists specifically for adding to the legend (aka. Proxy artists)
63
67
===========================================================================
64
68
0 commit comments