Sngr

python读取数据画折线图
temp.txt模板为2019-09-22 16:40#25 2019-09-22 16:41#25 2019-0...
扫描右侧二维码阅读全文
22
2019/09

python读取数据画折线图

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
If you think my article is useful to you, please feel free to appreciate

One comment

  1. Sngr

    #设置Y轴的范围
    plt.ylim(0,40)

Leave a Comment