.. _sphx_glr_gallery_userdemo_simple_legend01.py: =============== Simple Legend01 =============== .. image:: /gallery/userdemo/images/sphx_glr_simple_legend01_001.png :align: center .. code-block:: python import matplotlib.pyplot as plt plt.subplot(211) plt.plot([1, 2, 3], label="test1") plt.plot([3, 2, 1], label="test2") # Place a legend above this subplot, expanding itself to # fully use the given bounding box. plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=2, mode="expand", borderaxespad=0.) plt.subplot(223) plt.plot([1, 2, 3], label="test1") plt.plot([3, 2, 1], label="test2") # Place a legend to the right of this smaller subplot. plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) plt.show() **Total running time of the script:** ( 0 minutes 0.045 seconds) .. only :: html .. container:: sphx-glr-footer .. container:: sphx-glr-download :download:`Download Python source code: simple_legend01.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: simple_legend01.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_