我有一个示例文本文件,如下所示:(test.txt)
06:00:41 2
06:10:41 4
06:20:41 6
06:25:41 8
我想将此X轴采用时间值和第二列绘制到y轴。
import matplotlib.pyplot as plt
import datetime
import matplotlib.dates as mdates
import time
import numpy as np
f2 = open('test.txt', 'r')
lines = f2.readlines()
f2.close()
x1 = []
y1 = []
for line in lines:
p = line.split()
a = time.strptime((p[0]),"%H:%M:%S")
x1.append((a))
y1.append(float(p[1]))
xv = np.array(x1)
yv = np.array(y1)
plt.plot(xv, yv)
plt.show()
这是我绘制它的方式。但X轴显示500,1000,1500等。相反,我想将时间值显示为06:00:41,06:10:41,06:20:41等请帮助我?