{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Legend guide\n\nGenerating legends flexibly in Matplotlib.\n\n.. currentmodule:: matplotlib.pyplot\n\nThis legend guide is an extension of the documentation available at\n:func:`~matplotlib.pyplot.legend` - please ensure you are familiar with\ncontents of that documentation before proceeding with this guide.\n\n\nThis guide makes use of some common terms, which are documented here for\nclarity:\n\n.. glossary::\n\n legend entry\n A legend is made up of one or more legend entries. An entry is made up\n of exactly one key and one label.\n\n legend key\n The colored/patterned marker to the left of each legend label.\n\n legend label\n The text which describes the handle represented by the key.\n\n legend handle\n The original object which is used to generate an appropriate entry in\n the legend.\n\n\n## Controlling the legend entries\n\nCalling :func:`legend` with no arguments automatically fetches the legend\nhandles and their associated labels. This functionality is equivalent to::\n\n handles, labels = ax.get_legend_handles_labels()\n ax.legend(handles, labels)\n\nThe :meth:`~matplotlib.axes.Axes.get_legend_handles_labels` function returns\na list of handles/artists which exist on the Axes which can be used to\ngenerate entries for the resulting legend - it is worth noting however that\nnot all artists can be added to a legend, at which point a \"proxy\" will have\nto be created (see `proxy_legend_handles` for further details).\n\n
Artists with an empty string as label or with a label starting with an\n underscore, \"_\", will be ignored.