
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/date.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_examples_date.py>`
        to download the full example code.

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

.. _sphx_glr_examples_date.py:


Datetime data
=============

mplcursors correctly formats datetime data.

.. GENERATED FROM PYTHON SOURCE LINES 7-24



.. image-sg:: /examples/images/sphx_glr_date_001.png
   :alt: date
   :srcset: /examples/images/sphx_glr_date_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


    import datetime as dt
    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.dates as mdates
    import mplcursors

    t = mdates.drange(dt.datetime(2014, 1, 15), dt.datetime(2014, 2, 27),
                      dt.timedelta(hours=2))
    y = np.sin(t)
    fig, ax = plt.subplots()
    ax.plot(mdates.num2date(t), y, "-")

    # Note that mplcursors will automatically display the x-values as dates.
    mplcursors.cursor()

    plt.show()


.. _sphx_glr_download_examples_date.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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