【发布时间】:2013-03-06 20:58:33
【问题描述】:
我在 python 中有一个带有日期(日期时间)的向量。如何从该向量上的出现中绘制具有 15 分钟 bin 的直方图?
这是我所做的:
StartTime = []
for b in myEvents:
StartTime.append(b['logDate'].time())
如您所见,我将日期转换为时间。 (我从 mongoDB 查询中获取 myEvents)
fig2 = plt.figure()
ax = fig2.add_subplot(111)
ax.grid(True,which='both')
ax.hist(StartTime,100)
我得到的错误是:
TypeError: can't compare datetime.time to float
我理解错误,但我不知道如何解决它。
非常感谢您的帮助
【问题讨论】:
-
您必须将
time转换为float,因为这是直方图函数唯一可以理解的内容。您可能会发现 this code 很有帮助。 -
@askewchan 我已经阅读了这个问题,但无法使用它
-
@Floris,感谢您的链接...不可能没有更优雅的方式来做到这一点...。使用您的建议,我需要稍后转换轴再次从 ms 回到 HH:MM...
标签: python datetime matplotlib histogram