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

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

.. _sphx_glr_gallery_axisartist_simple_axis_pad.py:


===============
Simple axis pad
===============

.. GENERATED FROM PYTHON SOURCE LINES 7-106



.. image-sg:: /gallery/axisartist/images/sphx_glr_simple_axis_pad_001.png
   :alt: simple axis pad
   :srcset: /gallery/axisartist/images/sphx_glr_simple_axis_pad_001.png, /gallery/axisartist/images/sphx_glr_simple_axis_pad_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
        tr = 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()

        grid_helper = GridHelperCurveLinear(tr,
                                            extreme_finder=extreme_finder,
                                            grid_locator1=grid_locator1,
                                            grid_locator2=grid_locator2,
                                            tick_formatter1=tick_formatter1
                                            )

        ax1 = fig.add_subplot(
            rect, axes_class=axisartist.Axes, grid_helper=grid_helper)
        ax1.axis[:].set_visible(False)
        ax1.set_aspect(1.)
        ax1.set_xlim(-5, 12)
        ax1.set_ylim(-5, 10)

        return ax1


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

        return axis


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

        return axis


    fig = plt.figure(figsize=(9, 3.))
    fig.subplots_adjust(left=0.01, right=0.99, bottom=0.01, top=0.99,
                        wspace=0.01, hspace=0.01)


    def ann(ax1, d):
        if plt.rcParams["text.usetex"]:
            d = d.replace("_", r"\_")

        ax1.annotate(d, (0.5, 1), (5, -5),
                     xycoords="axes fraction", textcoords="offset points",
                     va="top", ha="center")


    ax1 = setup_axes(fig, rect=141)
    axis = add_floating_axis1(ax1)
    ann(ax1, r"default")

    ax1 = setup_axes(fig, rect=142)
    axis = add_floating_axis1(ax1)
    axis.major_ticklabels.set_pad(10)
    ann(ax1, r"ticklabels.set_pad(10)")

    ax1 = setup_axes(fig, rect=143)
    axis = add_floating_axis1(ax1)
    axis.label.set_pad(20)
    ann(ax1, r"label.set_pad(20)")

    ax1 = setup_axes(fig, rect=144)
    axis = add_floating_axis1(ax1)
    axis.major_ticks.set_tick_out(True)
    ann(ax1, "ticks.set_tick_out(True)")

    plt.show()


.. _sphx_glr_download_gallery_axisartist_simple_axis_pad.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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