I am plotting data with matplotlib.
I would like to watch the data being plotted over a few seconds time.
Current script (below) is close.. It closes the existing plot and makes a new plot including one additional data point for each while loop iteration.
If the "fig=" and "ax1=" statements are instead typed above the loop, I get only a blank plot.
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
import time
#import matplotlib.animation as animation
def animate2(i):
k=1
#fig=plt.figure()
#ax1=fig.add_subplot(1, 1, 1)
while k <=len(i):
fig=plt.figure()
ax1=fig.add_subplot(1, 1, 1)
ax1.clear
ax1.plot(i[0:k, 0], i[0:k, 1])
plt.show()
time.sleep(1)
k=k+1
Here the a sample np array I've used:
test_data=np.array([[3, 7],[1, 2],[8, 11],[5, -12],[20, 25], [-3, 30], [2,2], [17, 17]])
animate2(test_data)
Also, if you think matplotlib.animation would work better, please provide an example!