Sep-23-2021, 03:47 PM
Hi, I was trying to understand myplotlib animation. Watched few tutorial videos and prepared the below code which is pretty much a copy/paste from one of the tutorials. I am trying to run this in Spyder 4.1.5.
I was expecting to see an animated plot when I run this code, but all I get is a blank figure and xcord and ycord lists printed once.
Can someone help and point out what am I doing wrong?
I was expecting to see an animated plot when I run this code, but all I get is a blank figure and xcord and ycord lists printed once.
Can someone help and point out what am I doing wrong?
import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation from itertools import count import random xcord = [] ycord = [5] index = count() xcord.append(next(index)) def animate(i): xcord.append(next(index)) ycord.append(random.randint(0,5)) plt.cla() plt.plot(xcord,ycord) fig, ax = plt.subplots(1,1) print(xcord) print(ycord) ani = FuncAnimation(fig,animate,interval=1000) plt.tight_layout() plt.show()
Output:runfile('D:/PJV/IT Reboot/matplotlibtest.py', wdir='D:/PJV/IT Reboot')
[0]
[5]