I want to plot a MatPlotLib.PyPlot graph, which is updated over time, and doesn't block program execution. I don't want the user to have to press a key to display the new graph each time it is updated.
I believe that plt.show(block=False) is required for what I want. However, my code does not perform as desired.
Here is my code:
import matplotlib.pyplot as plt
import time
def ShowGraph():
n = 2
while True:
x = [i for i in range(n)]
y = [i for i in range(n)]
plt.plot(x, y, 'r-')
plt.ylim([0, 10])
plt.xlim([0, 10])
plt.show(block=False)
time.sleep(1)
n += 1
ShowGraph()
This should plot a new graph every second, with the red line getting longer each time. However, all that shows is the graph after the first call to plt.show(). What am I doing wrong?