Placing date ticks using recurrence rulesΒΆ

The iCalender RFC specifies recurrence rules (rrules), that define date sequences. You can use rrules in Matplotlib to place date ticks.

This example sets custom date ticks on every 5th easter.

See for help with rrules.

date demo rrule
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

# 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)
ax.xaxis.set_tick_params(rotation=30, labelsize=10)

Keywords: matplotlib code example, codex, python plot, pyplot Gallery generated by Sphinx-Gallery