【发布时间】:2017-11-25 04:55:23
【问题描述】:
我想绘制一个索引为无数 DatatimeIndex 的熊猫系列。我的代码如下:
import matplotlib.dates as mdates
index = pd.DatetimeIndex(['2000-01-01 00:00:00', '2000-01-01 00:01:00',
'2000-01-01 00:02:00', '2000-01-01 00:03:00',
'2000-01-01 00:07:00',
'2000-01-01 00:08:00'],
dtype='datetime64[ns]')
df = pd.Series(range(6), index=index)
print(df)
plt.plot(df.index, df.values)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter("%M"))
plt.show()
输出为: 但结果并不是我真正想要的,因为 2000-01-01 00:04:00 也绘制在图像上。期望的结果是在 x 轴上 03:00 在 07:00 旁边,并且图像应该是一条直线。希望你的好主意。
【问题讨论】:
标签: python pandas matplotlib series