Python 如何将时间戳设置为初始值(0)
我有一个来自数据库的时间戳,需要绘制一个图(速率与时间)。我有流程开始和结束时的时间戳,但我需要使开始时间戳等于0分钟(初始值),结束值等于20-30分钟(取决于试验)。我不知道该用什么 此外,我将速率作为列表,需要将它们放入matplotlib的数组中。我使用了np.asarray(),它说类型是一个数组,但它在我的绘图上只给了我一个数字(最后一个数字)。有没有办法解决这个问题 代码:Python 如何将时间戳设置为初始值(0),python,arrays,matplotlib,time,timestamp,Python,Arrays,Matplotlib,Time,Timestamp,我有一个来自数据库的时间戳,需要绘制一个图(速率与时间)。我有流程开始和结束时的时间戳,但我需要使开始时间戳等于0分钟(初始值),结束值等于20-30分钟(取决于试验)。我不知道该用什么 此外,我将速率作为列表,需要将它们放入matplotlib的数组中。我使用了np.asarray(),它说类型是一个数组,但它在我的绘图上只给了我一个数字(最后一个数字)。有没有办法解决这个问题 代码: 请张贴您的代码,以便我们提供帮助。您的时间戳是否转换为日期时间?我添加了代码。我想时间戳没有转换成datet
请张贴您的代码,以便我们提供帮助。您的时间戳是否转换为日期时间?我添加了代码。我想时间戳没有转换成datetime,因为我把它转换成了一个float。你的时间戳是
20080506043555
?该数字太大,无法作为有效日期。它是如何定义的?它应该是2008年5月6日4:34:43秒555毫秒扫描您打印的时间L3time
。它看起来像是一个刚刚被分解的时间元素数组。matplotlib也可以使用列表,它不必是数组。请发布您的代码,以便我们提供帮助。您的时间戳是否转换为日期时间?我添加了代码。我想时间戳没有转换成datetime,因为我把它转换成了一个float。你的时间戳是20080506043555
?该数字太大,无法作为有效日期。它是如何定义的?它应该是2008年5月6日4:34:43秒555毫秒扫描您打印的时间L3time
。它看起来像是一个刚刚被分解的时间元素数组。matplotlib也可以使用列表,它不必是数组。
# timestamp comes out as 2.0080506043443555 e-16 because of the float
# need to change that into minutes for each run
L3time = L3timestamp.split()
del L3time[0]
for k in range(0, len(L3time)):
print(float(L3time[k]))
#print("this is the L3 rates")
for k in range(1, len(L3time)):
L3rate = (float(L3[k]) - float(L3[k-1]))*1000/(float(L3time[k]) - float(L3time[k-1]))
print(float(L3rate))
# putting the L3 rate into an array
L3RateArray = np.asarray(L3rate)
# putting the timestamp into an array
timestampArray = np.asarray(L3time)
for k in inFile.readlines():
plt.plot([timestampArray], [L3RateArray], 'ro')
plt.xlabel("time (m)")
plt.ylabel("L3 Rates (Hz)")
plt.suptitle("L3 Rates vs. Time")
plt.show()