2
I’m doing a program for Raspberry Pi that scans temperature sensors and stores these readings in a buffer. I need to make a dynamic graph that shows the relationship between temperature and current time. I tried using the matplotlib library, but I can’t update this graph.
In the code below, when I use the append method I add the values obtained in the temperature reading.
import matplotlib.pyplot as plt
temperatura = [10, 20, 30 ,40 , 50 ,60 , 70, 80]
tempo = [1, 2, 3, 4, 5, 6, 7, 8]
plt.plot(tempo, temperatura )
plt.ylabel('Temperatura (C°)')
plt.xlabel('Tempo (S)')
plt.show()
temperatura.append(90)
tempo.append(9)
plt.plot(tempo, temperatura )
plt.show()
When running the program the graph with the initial values is shown, but only when closing the graph does it open the other graph with the updated values!
You have two
plt.show()
in your code.– Giovanni Nunes
Yes, to try to update the chart!
– HelloWorld
According to the documentation it is possible to use
plt.show(block=False)
so that he does not wait for the drawing to be closed.– Giovanni Nunes
Said "according to the documentation" because it says it is an experimental implementation :-)
– Giovanni Nunes
This link has what you are looking for https://pythonprogramming.net/python-matplotlib-live-updating-graphs/
– XronoX