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

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

.. _sphx_glr_gallery_ticks_engformatter_offset.py:


===================================================
SI prefixed offsets and natural order of magnitudes
===================================================

`matplotlib.ticker.EngFormatter` is capable of computing a natural
offset for your axis data, and presenting it with a standard SI prefix
automatically calculated.

Below is an examples of such a plot:

.. GENERATED FROM PYTHON SOURCE LINES 13-34



.. image-sg:: /gallery/ticks/images/sphx_glr_engformatter_offset_001.png
   :alt: engformatter offset
   :srcset: /gallery/ticks/images/sphx_glr_engformatter_offset_001.png, /gallery/ticks/images/sphx_glr_engformatter_offset_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    import matplotlib.ticker as mticker

    # Fixing random state for reproducibility
    np.random.seed(19680801)

    UNIT = "Hz"

    fig, ax = plt.subplots()
    ax.yaxis.set_major_formatter(mticker.EngFormatter(
        useOffset=True,
        unit=UNIT
    ))
    size = 100
    measurement = np.full(size, 1e9)
    noise = np.random.uniform(low=-2e3, high=2e3, size=size)
    ax.plot(measurement + noise)
    plt.show()


.. _sphx_glr_download_gallery_ticks_engformatter_offset.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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