I have 4 variables like this:
# 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) And I need to create one figure with 4 subplots.
so I tried this:
plt.figure(figsize=(9,3)) plt.subplot(1,4,1) plt.hist(x1, normed=True, bins=20, alpha=0.5) plt.subplot(1,4,2) plt.hist(x2, normed=True, bins=20, alpha=0.5) plt.subplot(1,4,3) plt.hist(x3, normed=True, bins=20, alpha=0.5) plt.subplot(1,4,4) plt.hist(x4, normed=True, bins=20, alpha=0.5) plt.axis([-7,21,0,0.6]) And I got this result
Now I want to create an animation on the subplots, so I did the following (trying one subplot only)
import matplotlib.animation as animation def update(curr): if curr == n: a.event_source.stop() plt.cla() plt.figure(figsize=(9,3)) plt.subplot(1,4,1) plt.hist(x1, normed=True, bins=20, alpha=0.5) plt.axis([-7,21,0,0.6]) plt.gca().set_title('Sample') plt.gca().set_ylabel('Frequency') plt.gca().set_xlabel('Value') plt.annotate('n = {}'.format(curr), [3.27]) fig = plt.figure() a = animation.FuncAnimation(fig, update, interval=100) However the end result is empty, nothing is shown.
Any idea?

