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
#2
Can someone help with this please?
If I add some print statements within my animate(i) function, those are not getting printed.
It seems animate(i) is not getting called from FuncAnimate(). I am stuck with this. Appreciate any help
Reply
#3
My problem seems to be with Anaconda/Spyder. I tried a fresh install of python and tried some of the animation code in the REPL window of new install and it works. The same code does not work on Anaconda/Spyder window. Any config setting etc to be done on Anaconda for animation to work?
Reply
#4
Got an answer from Stack Overflow. In Spyder I need Tools->Preferences->Graphics->Backend to anything other than Inline. That fixed the issue.
Reply
#5
Thanks for posting this. I had tackled the problem and ran into similar headaches. Finally got it working, at least the sine wave and rain demos by using VSCode. I launch that from within Anaconda and use conda for managing the environment and it worked there.
Reply


Forum Jump:

User Panel Messages

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