I want to create a matplotlib animation, but instead of having matplotlib call me I want to call matplotlib. For example I want to do this:
from random import random
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
def update(frame):
plt.scatter(random(),random())
fig, ax = plt.subplots()
ani = FuncAnimation(fig, update, interval=340, repeat=True)
ani.save("my.mov", "avconv")
Like this:
def update():
plt.scatter(random(),random())
fig, ax = plt.subplots()
ani = MadeUpSubClassPassiveAnimation(fig)
while True:
update()
ani.update()
# do other stuff ...
ani.save("my.mov", "avconv")
I realize I could drive a live plot like this:
def update():
plt.scatter(x, y)
plt.pause(0.01)
fig, ax = plt.subplots()
plt.ion()
while True:
update()
time.sleep(1)
But AFAIK I need to use Animation
for the save()
functionality. So, is it possible to drive Animation
rather than have it drive me? If so how?