

.. _sphx_glr_gallery_pylab_examples_date_demo_rrule.py:


===============
Date Demo Rrule
===============

Show how to use an rrule instance to make a custom date ticker - here
we put a tick mark on every 5th easter

See https://moin.conectiva.com.br/DateUtil for help with rrules




.. image:: /gallery/pylab_examples/images/sphx_glr_date_demo_rrule_001.png
    :align: center





.. code-block:: python

    import matplotlib.pyplot as plt
    from matplotlib.dates import YEARLY, DateFormatter, rrulewrapper, RRuleLocator, drange
    import numpy as np
    import datetime

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


    # tick every 5th easter
    rule = rrulewrapper(YEARLY, byeaster=1, interval=5)
    loc = RRuleLocator(rule)
    formatter = DateFormatter('%m/%d/%y')
    date1 = datetime.date(1952, 1, 1)
    date2 = datetime.date(2004, 4, 12)
    delta = datetime.timedelta(days=100)

    dates = drange(date1, date2, delta)
    s = np.random.rand(len(dates))  # make up some random y values


    fig, ax = plt.subplots()
    plt.plot_date(dates, s)
    ax.xaxis.set_major_locator(loc)
    ax.xaxis.set_major_formatter(formatter)
    labels = ax.get_xticklabels()
    plt.setp(labels, rotation=30, fontsize=10)

    plt.show()

**Total running time of the script:** ( 0 minutes  0.066 seconds)



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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

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

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