
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/text_labels_and_annotations/legend.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

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

        :ref:`Go to the end <sphx_glr_download_gallery_text_labels_and_annotations_legend.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_text_labels_and_annotations_legend.py:


===============================
Legend using pre-defined labels
===============================

Defining legend labels with plots.

.. GENERATED FROM PYTHON SOURCE LINES 8-31

.. code-block:: Python



    import matplotlib.pyplot as plt
    import numpy as np

    # Make some fake data.
    a = b = np.arange(0, 3, .02)
    c = np.exp(a)
    d = c[::-1]

    # Create plots with pre-defined labels.
    fig, ax = plt.subplots()
    ax.plot(a, c, 'k--', label='Model length')
    ax.plot(a, d, 'k:', label='Data length')
    ax.plot(a, c + d, 'k', label='Total message length')

    legend = ax.legend(loc='upper center', shadow=True, fontsize='x-large')

    # Put a nicer background color on the legend.
    legend.get_frame().set_facecolor('C0')

    plt.show()




.. image-sg:: /gallery/text_labels_and_annotations/images/sphx_glr_legend_001.png
   :alt: legend
   :srcset: /gallery/text_labels_and_annotations/images/sphx_glr_legend_001.png, /gallery/text_labels_and_annotations/images/sphx_glr_legend_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 32-39

.. admonition:: References

   The use of the following functions, methods, classes and modules is shown
   in this example:

   - `matplotlib.axes.Axes.plot` / `matplotlib.pyplot.plot`
   - `matplotlib.axes.Axes.legend` / `matplotlib.pyplot.legend`


.. _sphx_glr_download_gallery_text_labels_and_annotations_legend.py:

.. only:: html

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

    .. container:: sphx-glr-download sphx-glr-download-jupyter

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

    .. container:: sphx-glr-download sphx-glr-download-python

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: legend.zip <legend.zip>`


.. only:: html

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

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
