【发布时间】:2021-03-16 17:28:53
【问题描述】:
import matplotlib.animation as animation
import numpy as np
import matplotlib.pyplot as plt
n = 100
x = np.random.randn(n)
我无法看到这段代码的动画。谁能帮帮我?
#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)
【问题讨论】:
-
您可能需要
plt.ion()来启用动画...也许?
标签: python matplotlib animation