when you do not pass in any extra arguments. In this case, the labels are taken from the artist. You can specify them either at artist creation or by calling the :meth:`~.Artist.set_label` method on the artist:: ax.plot([1, 2, 3], label='Inline label') ax.legend() or:: line, = ax.plot([1, 2, 3]) line.set_label('Label via method') ax.legend() .. note:: Specific artists can be excluded from the automatic legend element selection by using a label starting with an underscore, "_". A string starting with an underscore is the default label for all artists, so calling `.Axes.legend` without any arguments and without setting the labels manually will result in no legend being drawn. **2. Explicitly listing the artists and labels in the legend** For full control of which artists have a legend entry, it is possible to pass an iterable of legend artists followed by an iterable of legend labels respectively:: ax.legend([line1, line2, line3], ['label1', 'label2', 'label3']) **3. Explicitly listing the artists in the legend** This is similar to 2, but the labels are taken from the artists' label properties. Example:: line1, = ax.plot([1, 2, 3], label='label1') line2, = ax.plot([1, 2, 3], label='label2') ax.legend(handles=[line1, line2]) **4. Labeling existing plot elements** .. admonition:: Discouraged This call signature is discouraged, because the relation between plot elements and labels is only implicit by their order and can easily be mixed up. To make a legend for all artists on an Axes, call this function with an iterable of strings, one for each legend item. For example:: ax.plot([1, 2, 3]) ax.plot([5, 6, 7]) ax.legend(['First line', 'Second line']) Parameters ---------- handles : sequence of (`.Artist` or tuple of `.Artist`), optional A list of Artists (lines, patches) to be added to the legend. Use this together with *labels*, if you need full control on what is shown in the legend and the automatic mechanism described above is not sufficient. The length of handles and labels should be the same in this case. If they are not, they are truncated to the smaller length. If an entry contains a tuple, then the legend handler for all Artists in the tuple will be placed alongside a single label. labels : list of str, optional A list of labels to show next to the artists. Use this together with *handles*, if you need full control on what is shown in the legend and the automatic mechanism described above is not sufficient. Returns ------- `~matplotlib.legend.Legend` Other Parameters ---------------- %(_legend_kw_axes)s See Also -------- .Figure.legend Notes ----- Some artists are not supported by this function. See :ref:`legend_guide` for details. Examples -------- .. plot:: gallery/text_labels_and_annotations/legend.py )