I have the following animated subplots that simulate histograms of four different distributions:
import numpy
from matplotlib.pylab import *
import matplotlib.animation as animation
n = 100
# 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)
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
def updateData(curr):
if curr == n:
a.event_source.stop()
ax1.hist(x1[:curr], normed=True, bins=20, alpha=0.5)
ax2.hist(x2[:curr], normed=True, bins=20, alpha=0.5)
ax3.hist(x3[:curr], normed=True, bins=20, alpha=0.5)
ax4.hist(x4[:curr], normed=True, bins=20, alpha=0.5)
simulation = animation.FuncAnimation(fig, updateData, interval=20, repeat=False)
plt.show()
It works, but for some reason the normed=True is being ignored for the y-axis scaling. If I take these plots out of the animation, they scale properly. How do I get proper scaling in the animation?
EDIT