Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Maptplotlib Animation
#1
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?

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]
Reply


Messages In This Thread
Maptplotlib Animation - by peterjv26 - Sep-23-2021, 03:47 PM
RE: Maptplotlib Animation - by peterjv26 - Sep-24-2021, 06:20 AM
RE: Maptplotlib Animation - by peterjv26 - Sep-26-2021, 07:41 AM
RE: Maptplotlib Animation - by peterjv26 - Sep-26-2021, 10:19 AM
RE: Maptplotlib Animation - by jefsummers - Sep-26-2021, 12:00 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020