temp.txt模板为

2019-09-22 16:40#25
2019-09-22 16:41#25
2019-09-22 16:42#25
2019-09-22 16:43#25
2019-09-22 16:44#25
2019-09-22 16:45#25

Python:

from matplotlib import pyplot as plt
from datetime import datetime
input_txt = '/root/notebook/temp.txt'
x = []
y = []
f = open(input_txt)
for line in f:
    line = line.strip('\n')
    line = line.split('#')
    x.append(datetime.strptime(line[0], '%Y-%m-%d %H:%M'))
    y.append(int(line[1]))
f.close
plt.plot(x, y, marker='o', label='lost plot')
plt.xticks(x[0:len(x):1], x[0:len(x):1], rotation=45)
plt.margins(0)
plt.xlabel("Datetime")
plt.ylabel("Temperature")
plt.title("Temperature by Datetime")
plt.tick_params(axis="both")
plt.savefig("temp.png")

实时温度:
请输入图片描述

ref:https://www.cnblogs.com/OliverQin/p/8978004.html

Last modification:September 22nd, 2019 at 08:19 pm