
.. 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_demo.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_demo.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_pie_and_polar_charts_polar_demo.py:


==========
Polar plot
==========

Demo of a line plot on a polar axis.

The second plot shows the same data, but with the radial axis starting at r=1
and the angular axis starting at 0 degrees and ending at 225 degrees. Setting
the origin of the radial axis to 0 allows the radial ticks to be placed at the
same location as the first plot.

.. GENERATED FROM PYTHON SOURCE LINES 13-44

.. code-block:: Python

    import matplotlib.pyplot as plt
    import numpy as np

    r = np.arange(0, 2, 0.01)
    theta = 2 * np.pi * r

    fig, axs = plt.subplots(2, 1, figsize=(5, 8), subplot_kw={'projection': 'polar'},
                            layout='constrained')
    ax = axs[0]
    ax.plot(theta, r)
    ax.set_rmax(2)
    ax.set_rticks([0.5, 1, 1.5, 2])  # Fewer radial ticks
    ax.set_rlabel_position(-22.5)  # Move radial labels away from plotted line
    ax.grid(True)

    ax.set_title("A line plot on a polar axis", va='bottom')

    ax = axs[1]
    ax.plot(theta, r)
    ax.set_rmax(2)
    ax.set_rmin(1)  # Change the radial axis to only go from 1 to 2
    ax.set_rorigin(0)  # Set the origin of the radial axis to 0
    ax.set_thetamin(0)
    ax.set_thetamax(225)
    ax.set_rticks([1, 1.5, 2])  # Fewer radial ticks
    ax.set_rlabel_position(-22.5)  # Move radial labels away from plotted line

    ax.grid(True)
    ax.set_title("Same plot, but with reduced axis limits", va='bottom')
    plt.show()




.. image-sg:: /gallery/pie_and_polar_charts/images/sphx_glr_polar_demo_001.png
   :alt: A line plot on a polar axis, Same plot, but with reduced axis limits
   :srcset: /gallery/pie_and_polar_charts/images/sphx_glr_polar_demo_001.png, /gallery/pie_and_polar_charts/images/sphx_glr_polar_demo_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 45-63

.. 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.projections.polar`
   - `matplotlib.projections.polar.PolarAxes`
   - `matplotlib.projections.polar.PolarAxes.set_rticks`
   - `matplotlib.projections.polar.PolarAxes.set_rmin`
   - `matplotlib.projections.polar.PolarAxes.set_rorigin`
   - `matplotlib.projections.polar.PolarAxes.set_rmax`
   - `matplotlib.projections.polar.PolarAxes.set_rlabel_position`

.. tags::

   plot-type: polar
   level: beginner


.. _sphx_glr_download_gallery_pie_and_polar_charts_polar_demo.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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