I am trying to figure out how to speed up this animation. I want the whole thing to finish at 30 seconds.
I've tried adjusting the interval between frames, the save count, inside FuncAnimation, but it doesn't seem to work. Is there anyway to just set the total duration and have matplotlib squeeze everything into that time limit?
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation #1
n = 500
x = np.random.randn(n)
%matplotlib notebook
# generate 4 random variables from the random, gamma, exponential, and uniform distributions
x1 = np.random.normal(-2.5, 1, 10000)
x2 = np.random.gamma(2, 1.5, 10000)
x3 = np.random.exponential(2, 10000)+7
x4 = np.random.uniform(14,20, 10000)
def update(curr):
# check if animation is at the last frame, and if so, stop the animation a
if curr == n:
a.event_source.stop()
plt.cla()
plt.hist(x1[:curr], normed=True, bins=20, alpha=0.5)
plt.hist(x2[:curr], normed=True, bins=20, alpha=0.5)
plt.hist(x3[:curr], normed=True, bins=20, alpha=0.5)
plt.hist(x4[:curr], normed=True, bins=20, alpha=0.5)
plt.axis([-7,21,0,0.6])
plt.text(x1.mean()-1.5, 0.5, 'Normal')
plt.text(x2.mean()-1.5, 0.5, 'Gamma')
plt.text(x3.mean()-1.5, 0.5, 'Exponential')
plt.text(x4.mean()-1.5, 0.5, 'Uniform')
plt.annotate('n = {}'.format(curr), [3,27])
fig = plt.figure()
fig = plt.figure(figsize=(9,3))
a = animation.FuncAnimation(fig, update, interval=10, blit=True, save_count=500)
The final product looks like this: