I'm trying to make a real-time ploting graph for my raspberry pi temperature sensor. I would like to make a measure every for example 20 min and insert data to graph with that time at bottom.
I have this code, but the time
is in string format and matplot won't let me insert it to ylim
because it wants a int
what should I do please?
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)