

.. _sphx_glr_examples_date.py:


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

mplcursors correctly formats datetime data.




.. image:: /examples/images/sphx_glr_date_001.png
    :align: center





.. 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_date(t, y, "-")
    fig.autofmt_xdate()

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

    plt.show()



.. only :: html

 .. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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


.. only:: html

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

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