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

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

.. _sphx_glr_gallery_ticks_tick-locators.py:


=============
Tick locators
=============

Tick locators define the position of the ticks.

This example illustrates the usage and effect of the most common locators.

.. GENERATED FROM PYTHON SOURCE LINES 10-78

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    import matplotlib.ticker as ticker


    def setup(ax, title):
        """Set up common parameters for the Axes in the example."""
        # only show the bottom spine
        ax.yaxis.set_major_locator(ticker.NullLocator())
        ax.spines[['left', 'right', 'top']].set_visible(False)

        ax.xaxis.set_ticks_position('bottom')
        ax.tick_params(which='major', width=1.00, length=5)
        ax.tick_params(which='minor', width=0.75, length=2.5)
        ax.set_xlim(0, 5)
        ax.set_ylim(0, 1)
        ax.text(0.0, 0.2, title, transform=ax.transAxes,
                fontsize=14, fontname='Monospace', color='tab:blue')


    fig, axs = plt.subplots(8, 1, figsize=(8, 6))

    # Null Locator
    setup(axs[0], title="NullLocator()")
    axs[0].xaxis.set_major_locator(ticker.NullLocator())
    axs[0].xaxis.set_minor_locator(ticker.NullLocator())

    # Multiple Locator
    setup(axs[1], title="MultipleLocator(0.5, offset=0.2)")
    axs[1].xaxis.set_major_locator(ticker.MultipleLocator(0.5, offset=0.2))
    axs[1].xaxis.set_minor_locator(ticker.MultipleLocator(0.1))

    # Fixed Locator
    setup(axs[2], title="FixedLocator([0, 1, 5])")
    axs[2].xaxis.set_major_locator(ticker.FixedLocator([0, 1, 5]))
    axs[2].xaxis.set_minor_locator(ticker.FixedLocator(np.linspace(0.2, 0.8, 4)))

    # Linear Locator
    setup(axs[3], title="LinearLocator(numticks=3)")
    axs[3].xaxis.set_major_locator(ticker.LinearLocator(3))
    axs[3].xaxis.set_minor_locator(ticker.LinearLocator(31))

    # Index Locator
    setup(axs[4], title="IndexLocator(base=0.5, offset=0.25)")
    axs[4].plot([0]*5, color='white')
    axs[4].xaxis.set_major_locator(ticker.IndexLocator(base=0.5, offset=0.25))

    # Auto Locator
    setup(axs[5], title="AutoLocator()")
    axs[5].xaxis.set_major_locator(ticker.AutoLocator())
    axs[5].xaxis.set_minor_locator(ticker.AutoMinorLocator())

    # MaxN Locator
    setup(axs[6], title="MaxNLocator(n=4)")
    axs[6].xaxis.set_major_locator(ticker.MaxNLocator(4))
    axs[6].xaxis.set_minor_locator(ticker.MaxNLocator(40))

    # Log Locator
    setup(axs[7], title="LogLocator(base=10, numticks=15)")
    axs[7].set_xlim(10**3, 10**10)
    axs[7].set_xscale('log')
    axs[7].xaxis.set_major_locator(ticker.LogLocator(base=10, numticks=15))

    plt.tight_layout()
    plt.show()




.. image-sg:: /gallery/ticks/images/sphx_glr_tick-locators_001.png
   :alt: tick locators
   :srcset: /gallery/ticks/images/sphx_glr_tick-locators_001.png, /gallery/ticks/images/sphx_glr_tick-locators_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 79-93

.. admonition:: References

   The following functions, methods, classes and modules are used in this example:

   - `matplotlib.axis.Axis.set_major_locator`
   - `matplotlib.axis.Axis.set_minor_locator`
   - `matplotlib.ticker.NullLocator`
   - `matplotlib.ticker.MultipleLocator`
   - `matplotlib.ticker.FixedLocator`
   - `matplotlib.ticker.LinearLocator`
   - `matplotlib.ticker.IndexLocator`
   - `matplotlib.ticker.AutoLocator`
   - `matplotlib.ticker.MaxNLocator`
   - `matplotlib.ticker.LogLocator`


.. _sphx_glr_download_gallery_ticks_tick-locators.py:

.. only:: html

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

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

      :download:`Download Jupyter notebook: tick-locators.ipynb <tick-locators.ipynb>`

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

      :download:`Download Python source code: tick-locators.py <tick-locators.py>`

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

      :download:`Download zipped: tick-locators.zip <tick-locators.zip>`


.. only:: html

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

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