演示日期Rrule
展示如何使用Rrule实例制作自定义日期自动收报机 - 这里我们在每5个复活节放置一个刻度线。
有关Rrules的帮助,请参阅https://dateutil.readthedocs.io/en/stable/

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| import matplotlib.pyplot as plt from matplotlib.dates import (YEARLY, DateFormatter, rrulewrapper, RRuleLocator, drange) import numpy as np import datetime
np.random.seed(19680801)
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))
fig, ax = plt.subplots() plt.plot_date(dates, s) ax.xaxis.set_major_locator(loc) ax.xaxis.set_major_formatter(formatter) ax.xaxis.set_tick_params(rotation=30, labelsize=10)
plt.show()
|
下载这个示例