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

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

.. _sphx_glr_gallery_units_units_scatter.py:


=============
Unit handling
=============

The example below shows support for unit conversions over masked
arrays.

.. only:: builder_html

   This example requires :download:`basic_units.py <basic_units.py>`

.. GENERATED FROM PYTHON SOURCE LINES 13-32



.. image-sg:: /gallery/units/images/sphx_glr_units_scatter_001.png
   :alt: units scatter
   :srcset: /gallery/units/images/sphx_glr_units_scatter_001.png, /gallery/units/images/sphx_glr_units_scatter_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. code-block:: Python

    from basic_units import hertz, minutes, secs

    import matplotlib.pyplot as plt
    import numpy as np

    # create masked array
    data = (1, 2, 3, 4, 5, 6, 7, 8)
    mask = (1, 0, 1, 0, 0, 0, 1, 0)
    xsecs = secs * np.ma.MaskedArray(data, mask, float)

    fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, sharex=True)

    ax1.scatter(xsecs, xsecs)
    ax1.yaxis.set_units(secs)
    ax2.scatter(xsecs, xsecs, yunits=hertz)
    ax3.scatter(xsecs, xsecs, yunits=minutes)

    fig.tight_layout()
    plt.show()


.. _sphx_glr_download_gallery_units_units_scatter.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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