【发布时间】:2019-02-16 16:16:22
【问题描述】:
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
fig, ax = plt.subplots()
def animate(t):
x = np.random.normal(0,1,[1000,1])
y = np.random.normal(0,1,[1000,10])
for i,v in enumerate(range(y.shape[1])):
op = x
hop = y[:,[i]]
ax.clear()
ax.scatter(op,hop)
ani = FuncAnimation(fig,animate,interval=1000)
plt.show()
注意函数 animate() 有参数 t > animate(t)。我真的不明白为什么,因为 t 没有任何意义,它不依赖于代码中的任何内容。为什么这是必要的?如果我创建一个没有参数的函数 > animate() 并运行代码,我会收到以下错误:
TypeError: animate() takes 0 positional arguments but 1 was given
我很困惑为什么需要这个 t。它只是没有任何意义,它不传递任何信息。
【问题讨论】:
-
在 matplotlib 2.2.2 中对我来说很好
-
@Bazingaa 它运行时没有在动画函数中传递参数 t?
-
是的,它在 jupyter notebook 中对我来说是这样运行的。我使用了
from IPython.display import HTML,然后是HTML(ani.to_html5_video())。生成动画散布动画
标签: python-3.x matplotlib animation