I was given some code that is supposed to simulate an animation of a y-array being refreshed over time in a single plot figure. I want to show the plot in my terminal window (using Spyder 3.3.6/Anaconda 1.9.7 on a MAC 10.13.14) that refreshes the y-values after every interval over the 'for' loop. I have been given code from an instructor that is supposed to do the plotting - on his video it looks like an animation - using calls to various ax subroutines - but in my hands all I get is a single plot with the time=0 starting array values.
I have researched numerous blog posts for similar situations, and have studied the matplotlib manual; I have tried playing around with the various commands, and their placement, and arguments. The best I have done is to plot all the y-arrays on top of each other on a single plot (by commenting out the ax.clear() and plt.show(block=false) commands. I can easily generate new plots for each y-array. But I am in the woods as to what is going on with my code.
I am submitting the complete code so you can run it and see the results. Appreciate any light you can shed on this. Thanks.
import matplotlib.pyplot as plt
import numpy as np
y = numpy.zeros(10)
#set up plot
fig, ax=plt.subplots()
ax.plot(y)
ax.set_ylim([0,1])
plt.show(block=False)
#instructor note: "the block=False flag tells Python to throw the plot on the screen then keep moving".
for i in range(5):
y = np.random.random([10,1])
ax.clear()
ax.plot(y)
ax.set_ylim([0,1])
plt.show(block=False)
fig.canvas.draw()
#Instructor note: "These commands will update the plot to show the latest y values, and then keeps moving".
ax.clear()
ax.plot(y)
ax.set_ylim([0,1])
plt.show
fig.canvas.draw()