
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/pie_and_polar_charts/polar_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_pie_and_polar_charts_polar_legend.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_pie_and_polar_charts_polar_legend.py:


============
Polar legend
============

Using a legend on a polar-axis plot.

.. GENERATED FROM PYTHON SOURCE LINES 8-30

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    fig = plt.figure()
    ax = fig.add_subplot(projection="polar", facecolor="lightgoldenrodyellow")

    r = np.linspace(0, 3, 301)
    theta = 2 * np.pi * r
    ax.plot(theta, r, color="tab:orange", lw=3, label="a line")
    ax.plot(0.5 * theta, r, color="tab:blue", ls="--", lw=3, label="another line")
    ax.tick_params(grid_color="palegoldenrod")
    # For polar Axes, it may be useful to move the legend slightly away from the
    # Axes center, to avoid overlap between the legend and the Axes.  The following
    # snippet places the legend's lower left corner just outside the polar Axes
    # at an angle of 67.5 degrees in polar coordinates.
    angle = np.deg2rad(67.5)
    ax.legend(loc="lower left",
              bbox_to_anchor=(.5 + np.cos(angle)/2, .5 + np.sin(angle)/2))

    plt.show()




.. image-sg:: /gallery/pie_and_polar_charts/images/sphx_glr_polar_legend_001.png
   :alt: polar legend
   :srcset: /gallery/pie_and_polar_charts/images/sphx_glr_polar_legend_001.png, /gallery/pie_and_polar_charts/images/sphx_glr_polar_legend_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 31-46

.. 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`
   - `matplotlib.projections.polar`
   - `matplotlib.projections.polar.PolarAxes`

.. tags::

   component: legend
   plot-type: polar
   level: beginner


.. _sphx_glr_download_gallery_pie_and_polar_charts_polar_legend.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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