You are reading an old version of the documentation (v1.5.0). For the latest version see

We're updating the default styles for Matplotlib 2.0

Learn what to expect in the new updates


Previous topic

pylab_examples example code:

Next topic

pylab_examples example code:

This Page

pylab_examples example code: date_demo_rrule.pyΒΆ

(Source code, png, hires.png, pdf)

#!/usr/bin/env python
Show how to use an rrule instance to make a custom date ticker - here
we put a tick mark on every 5th easter

See for help with rrules
import matplotlib.pyplot as plt
from matplotlib.dates import YEARLY, DateFormatter, rrulewrapper, RRuleLocator, drange
import numpy as np
import datetime

# tick every 5th easter
rule = rrulewrapper(YEARLY, byeaster=1, interval=5)
loc = RRuleLocator(rule)
formatter = DateFormatter('%m/%d/%y')
date1 =, 1, 1)
date2 =, 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)
labels = ax.get_xticklabels()
plt.setp(labels, rotation=30, fontsize=10)

Keywords: python, matplotlib, pylab, example, codex (see Search examples)