【发布时间】:2016-11-23 12:57:51
【问题描述】:
我正在尝试针对某些迭代值绘制以秒为单位的持续时间。我通过减去两个日期时间值来计算持续时间值。然后,我想使用现有工具以非常简单的方式绘制这些结果。
我的代码如下,但还不行:
#!/usr/bin/env python
import datetime
import matplotlib.pyplot as plt
from numpy import arange
it = arange(10)
durations = [datetime.timedelta(hours=h+30) for h in it]
plt.plot(it, durations)
plt.show()
我收到以下错误:
TypeError: float() argument must be a string or a number
我知道我可以通过使用 datetime 而不是 timedelta 来使其工作,但我的目标是以小时为单位(大约 40 小时)绘制持续时间,因此渲染效果不佳。
【问题讨论】:
标签: python matplotlib timedelta