Reputation: 31
import matplotlib.animation as animation
import numpy as np
import matplotlib.pyplot as plt
n = 100
x = np.random.randn(n)
I could not be able to see the animation of this code. Can anyone help me?
#function
def update(curr):
if curr == n:
a.event_source.stop()
#graphs
plt.cla()
bins = np.arange(-4, 4, 0.5)
plt.hist(x[:curr], bins=bins)
plt.axis([-4,4,0,30])
plt.gca().set_title('Sampling the Normal Distribution')
plt.gca().set_ylabel('Frequency')
plt.gca().set_xlabel('Value')
plt.annotate('n = {}'.format(curr), [3,27])
fig = plt.figure()
#animation
a = animation.FuncAnimation(fig, update, interval=100)
Upvotes: 3
Views: 253
Reputation: 11
I didn't see the #function def update(curr): so I was writing a long answer on how to use the FuncAnimation method but I think all you need to do is add: plt.show()
after a = animation.FuncAnimation(fig, update, interval=100)
Upvotes: 1