我想绘制一些时间戳(年 - 月 - 日 - 小时 - 分钟 - 秒格式)。我使用下面的代码,但它不显示任何小时分秒信息,它将它们显示为00-00-00。我仔细检查了我的日期数组,并且从下面的代码片段可以看到,它们不是零。使用Matplotlib绘制时间戳(小时/分钟/秒)
你知道我为什么得到00-00-00吗?
import matplotlib.pyplot as plt
import matplotlib.dates as md
import dateutil
dates = [dateutil.parser.parse(s) for s in datestrings]
# datestrings = ['2012-02-21 11:28:17.980000', '2012-02-21 12:15:32.453000', '2012-02-21 23:26:23.734000', '2012-02-26 17:42:15.804000']
plt.subplots_adjust(bottom=0.2)
plt.xticks(rotation= 80)
ax=plt.gca()
xfmt = md.DateFormatter('%Y-%m-%d %H:%M:%S')
ax.xaxis.set_major_formatter(xfmt)
plt.plot(dates[0:10],plt_data[0:10], "o-")
plt.show()
感谢您的回答。我已经看过“在matplotlib中绘制unix时间戳”问题。但是,我的问题是,Matplotlib不显示小时分秒,因为它显示在“绘制matplotlib中的unix时间戳”问题上。在我的情况下,它只是将它们显示为00-00-00,我找不出原因(因为它好像我的时间戳是正确的)。 – user1048858
你说得对,这是因为它试图用蜱填充x轴,看到我编辑的答案。 – seth