@@ -42,23 +42,27 @@ handles and their associated labels. This functionality is equivalent to::
4242
4343The :meth: `~matplotlib.axes.Axes.get_legend_handles_labels ` function returns
4444a 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).
4648
4749For full control of what is being added to the legend, it is common to pass
4850the appropriate handles directly to :func: `legend `::
4951
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 ])
5355
5456In some cases, it is not possible to set the label of the handle, so it is
5557possible to pass through the list of labels to :func: `legend `::
5658
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 '])
6062
6163
64+ .. _proxy_legend_handles :
65+
6266Creating artists specifically for adding to the legend (aka. Proxy artists)
6367===========================================================================
6468
0 commit comments