尝试pygal 中涉及日期时间或日期的 XY 图的示例代码,1970 年之前的任何日期都会导致此回溯:
Traceback (most recent call last):
File "C:/Users/***/dt_test.py", line 30, in <module>
datetimeline.render()
File "C:\Python\Python36\lib\site-packages\pygal\graph\public.py", line 52,
in render
self.setup(**kwargs)
File "C:\Python\Python36\lib\site-packages\pygal\graph\base.py", line 217,
in setup
self._draw()
File "C:\Python\Python36\lib\site-packages\pygal\graph\graph.py", line 924,
in _draw
self._compute_x_labels()
File "C:\Python\Python36\lib\site-packages\pygal\graph\dual.py", line 61,
in _compute_x_labels
self._x_labels = list(zip(map(self._x_format, x_pos), x_pos))
File "C:\Python\Python36\lib\site-packages\pygal\graph\time.py", line 103,
in datetime_to_str
dt = datetime.utcfromtimestamp(x)
OSError: [Errno 22] Invalid argument
有没有其他人得到这种行为?(我正在使用 PyCharm。)也许“千年”正在返回一个意外的负数?
(编辑)我使用了“日期”下的代码,在 PyCharm 中运行:
from datetime import datetime
datetimeline = pygal.DateTimeLine(
x_label_rotation=35, truncate_label=-1,
x_value_formatter=lambda dt: dt.strftime('%d, %b %Y at %I:%M:%S %p'))
datetimeline.add("Serie", [
(datetime(2013, 1, 2, 12, 0), 300),
(datetime(2013, 1, 12, 14, 30, 45), 412),
(datetime(2013, 2, 2, 6), 823),
(datetime(2013, 2, 22, 9, 45), 672)
])
datetimeline.render()
...当我将“2013”更改为“1969”时,我得到了上面显示的 Traceback。