【发布时间】:2015-12-21 19:39:46
【问题描述】:
我正在绘制 30 年的 Pandas 系列日期时间。 x 轴是日期:
Datetime
1965-06-08 3545
1965-06-09 6378
1965-06-10 9857
1965-06-11 2528
....
Freq: W-SUN, dtype: int64
我希望每个月都有一个“次要刻度”,每年都有一个“主要刻度”。
因为这是三十年的数据,手动放置刻度是行不通的。
基于 matplotlib 的日期 API,http://matplotlib.org/api/dates_api.html
是否可以在每个月设置一个刻度?
如果我要手动设置网格,我会这样做:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
# This is where I manually set ticks. Can I use Datetime data instead???
major_ticks = np.arange(0, 101, 20)
minor_ticks = np.arange(0, 101, 5)
ax.set_xticks(major_ticks)
ax.set_xticks(minor_ticks, minor=True)
ax.set_yticks(major_ticks)
ax.set_yticks(minor_ticks, minor=True)
ax.grid(which='both')
ax.grid(which='minor', alpha=0.3)
ax.grid(which='major', alpha=0.4)
plt.show()
【问题讨论】:
标签: python numpy pandas matplotlib