| [ Web Proxy ] |
| Viewing: https://matplotlib.org/gallery/mplot3d/../showcase/../mplot3d/../ticks/date_demo_rrule.html | [Back] [Original] |
Section Navigation
fill_between with transparencyhisttype settingsplt.subplotsfloating_axes featuresNote
Go to the end to download the full example code.
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 https://dateutil.readthedocs.io/en/stable/rrule.html for help with rrules.
[date demo rrule]import datetime
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.dates import YEARLY, DateFormatter, RRuleLocator, drange, rrulewrapper
# 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(dates, s, 'o')
ax.xaxis.set_major_locator(loc)
ax.xaxis.set_major_formatter(formatter)
ax.xaxis.set_tick_params(rotation=30, labelsize=10)
plt.show()
Copyright 20022012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 20122026 The Matplotlib development team.
Created using Sphinx 9.1.0.
Built from v3.11.2-1-g879ad8ebba.
Built with the PyData Sphinx Theme 0.16.1.
| Web Proxy Viewer | New URL | Original Page |