Python Forum
Maptplotlib Animation - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Maptplotlib Animation (/thread-35012.html)



Maptplotlib Animation - peterjv26 - Sep-23-2021

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]



RE: Maptplotlib Animation - peterjv26 - Sep-24-2021

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


RE: Maptplotlib Animation - peterjv26 - Sep-26-2021

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?


RE: Maptplotlib Animation - peterjv26 - Sep-26-2021

Got an answer from Stack Overflow. In Spyder I need Tools->Preferences->Graphics->Backend to anything other than Inline. That fixed the issue.


RE: Maptplotlib Animation - jefsummers - Sep-26-2021

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.