【发布时间】:2019-04-27 08:41:12
【问题描述】:
我正在尝试为我的树莓派温度传感器制作实时绘图图。我想每隔例如 20 分钟进行一次测量,并将数据插入到底部的图形中。
我有这段代码,但time 是字符串格式,matplot 不允许我将它插入到ylim,因为它需要int,请问我该怎么办?
import matplotlib.pyplot as plt
import RPi.GPIO as GPIO
import dht11
import time
from drawnow import drawnow
# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()
# read data using pin 4
instance = dht11.DHT11(pin=4)
def make_fig():
plt.plot(x, y)
plt.ion()
fig = plt.figure()
x = list()
y = list()
while True:
result = instance.read()
tem = time.strftime("%H:%M:%S", time.localtime(time.time()))
x.append(tem)
y.append(result.temperature)
drawnow(make_fig)
time.sleep(1000)
【问题讨论】:
标签: python python-3.x matplotlib time