我正在编写一个脚本,在x轴上绘制一些带有日期的数据(在matplotlib中)。我需要在这些日期之外创建一个numpy.linspace
,以便在以后创建一个spline。有可能做到这一点吗?
我尝试过的:
import datetime
import numpy as np
dates = [
datetime.datetime(2015, 7, 2, 0, 31, 41),
datetime.datetime(2015, 7, 2, 1, 35),
datetime.datetime(2015, 7, 2, 2, 37, 9),
datetime.datetime(2015, 7, 2, 3, 59, 16),
datetime.datetime(2015, 7, 2, 5, 2, 23)
]
x = np.linspace(min(dates), max(dates), 500)
它抛出这个错误:
TypeError: unsupported operand type(s) for *: 'datetime.datetime' and 'float'
我也尝试过将datetime
转换为np.datetime64
,但效果不佳:
dates = [np.datetime64(i) for i in dates]
x = np.linspace(min(dates), max(dates), 500)
错误:
TypeError: ufunc multiply cannot use operands with types dtype('<M8[us]') and dtype('float64')
https://stackoverflow.com/questions/37964100
复制相似问题