.. note::
    :class: sphx-glr-download-link-note

    Click :ref:`here <sphx_glr_download_gallery_userdemo_simple_legend02.py>` to download the full example code
.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_userdemo_simple_legend02.py:


===============
Simple Legend02
===============





.. image:: /gallery/userdemo/images/sphx_glr_simple_legend02_001.png
    :class: sphx-glr-single-img





.. code-block:: python

    import matplotlib.pyplot as plt

    fig, ax = plt.subplots()

    line1, = ax.plot([1, 2, 3], label="Line 1", linestyle='--')
    line2, = ax.plot([3, 2, 1], label="Line 2", linewidth=4)

    # Create a legend for the first line.
    first_legend = ax.legend(handles=[line1], loc=1)

    # Add the legend manually to the current Axes.
    ax.add_artist(first_legend)

    # Create another legend for the second line.
    ax.legend(handles=[line2], loc=4)

    plt.show()


.. _sphx_glr_download_gallery_userdemo_simple_legend02.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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


.. only:: html

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

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
