I have to make an animation of a large number (~90,000) figures. For context, it\'s a plot of a map for every day from 1700 - 1950, with events of interest marked on relevent da
Same observations:
animate
a float number will be passedSo you can do the following:
import numpy as np
import matplotlib.pyplot as plt
from moviepy.video.io.bindings import mplfig_to_npimage
import moviepy.editor as mpy
fig = plt.figure()
ax = plt.axes()
x = np.random.randn(10, 1)
y = np.random.randn(10, 1)
p = plt.plot(x, y, 'ko')
time = np.arange(2341973, 2342373)
cache = {}
def animate(t):
i = int(t)
if i in cache:
return cache[i]
xn = x + np.sin(2 * np.pi * time[i] / 10.0)
yn = y + np.cos(2 * np.pi * time[i] / 8.0)
p[0].set_data(xn, yn)
cache.clear()
cache[i] = mplfig_to_npimage(fig)
return cache[i]
duration = len(time)
fps = 15
animation = mpy.VideoClip(animate, duration=duration)
animation.write_videofile("test.mp4", fps=fps)