Reputation: 81
Say I have a function plot(I) to plot an image like
def plot(I):
plt.imshow(I)
time.sleep(0.5)
plt.show(block=False)
And in my main program, I have a loop to update I like
if __name__ == "__main__":
I=some_input
for i in range(300):
I=update(I)
plot(I)
I want to display the updated images like a gif file but the code above failed like the plot does not update and I have to close the window so that it can be updated. Is there any way to achieve what I want like display images consecutively with matplotlib.
Upvotes: 1
Views: 442
Reputation: 81
I got it now. This should do the trick.
def plot(I):
plt.imshow(I,'gray')
plt.show(block=False)
plt.pause(0.5)
plt.clf()
This will plot I every 0.5 second.
Upvotes: 2