

.. _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.049 seconds)



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

     :download:`Download Python source code: simple_legend01.py <simple_legend01.py>`



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: simple_legend01.ipynb <simple_legend01.ipynb>`

.. rst-class:: sphx-glr-signature

    `Generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
