我正在编写一个脚本,用x轴绘制一些日期数据(在matplotlib中).我需要创建一个numpy.linspace超出这些日期,以便之后创建样条曲线.有可能吗?
我尝试过的:
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)
Run Code Online (Sandbox Code Playgroud)
它抛出此错误:
TypeError: unsupported operand type(s) for *: 'datetime.datetime' and 'float'
Run Code Online (Sandbox Code Playgroud)
我也尝试转换datetime到np.datetime64,但是,这并不工作,以及:
dates = [ np.datetime64(i) for i in dates ]
x = np.linspace(min(dates), max(dates), 500)
Run Code Online (Sandbox Code Playgroud)
错误:
TypeError: ufunc multiply …Run Code Online (Sandbox Code Playgroud)