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

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

.. _sphx_glr_gallery_axisartist_demo_axis_direction.py:


===================
axis_direction demo
===================

.. GENERATED FROM PYTHON SOURCE LINES 6-73



.. image-sg:: /gallery/axisartist/images/sphx_glr_demo_axis_direction_001.png
   :alt: bottom, left, top, right, bottom, left, top, right
   :srcset: /gallery/axisartist/images/sphx_glr_demo_axis_direction_001.png, /gallery/axisartist/images/sphx_glr_demo_axis_direction_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    from matplotlib.projections import PolarAxes
    from matplotlib.transforms import Affine2D
    import mpl_toolkits.axisartist as axisartist
    import mpl_toolkits.axisartist.angle_helper as angle_helper
    import mpl_toolkits.axisartist.grid_finder as grid_finder
    from mpl_toolkits.axisartist.grid_helper_curvelinear import \
        GridHelperCurveLinear


    def setup_axes(fig, rect):
        """Polar projection, but in a rectangular box."""
        # see demo_curvelinear_grid.py for details
        grid_helper = GridHelperCurveLinear(
            (
                Affine2D().scale(np.pi/180., 1.) +
                PolarAxes.PolarTransform(apply_theta_transforms=False)
            ),
            extreme_finder=angle_helper.ExtremeFinderCycle(
                20, 20,
                lon_cycle=360, lat_cycle=None,
                lon_minmax=None, lat_minmax=(0, np.inf),
            ),
            grid_locator1=angle_helper.LocatorDMS(12),
            grid_locator2=grid_finder.MaxNLocator(5),
            tick_formatter1=angle_helper.FormatterDMS(),
        )
        ax = fig.add_subplot(
            rect, axes_class=axisartist.Axes, grid_helper=grid_helper,
            aspect=1, xlim=(-5, 12), ylim=(-5, 10))
        ax.axis[:].toggle(ticklabels=False)
        ax.grid(color=".9")
        return ax


    def add_floating_axis1(ax):
        ax.axis["lat"] = axis = ax.new_floating_axis(0, 30)
        axis.label.set_text(r"$\theta = 30^{\circ}$")
        axis.label.set_visible(True)
        return axis


    def add_floating_axis2(ax):
        ax.axis["lon"] = axis = ax.new_floating_axis(1, 6)
        axis.label.set_text(r"$r = 6$")
        axis.label.set_visible(True)
        return axis


    fig = plt.figure(figsize=(8, 4), layout="constrained")

    for i, d in enumerate(["bottom", "left", "top", "right"]):
        ax = setup_axes(fig, rect=241+i)
        axis = add_floating_axis1(ax)
        axis.set_axis_direction(d)
        ax.set(title=d)

    for i, d in enumerate(["bottom", "left", "top", "right"]):
        ax = setup_axes(fig, rect=245+i)
        axis = add_floating_axis2(ax)
        axis.set_axis_direction(d)
        ax.set(title=d)

    plt.show()


.. _sphx_glr_download_gallery_axisartist_demo_axis_direction.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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