小编And*_*pez的帖子

python matplotlib:无法从函数内部调用FuncAnimation

我正在尝试实现一个输出动画情节的功能.

如果我将simple_anim.py(来自matplotlib示例)作为基础:

"""
 A simple example of an animated plot
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig, ax = plt.subplots()

x = np.arange(0, 2*np.pi, 0.01)        # x-array
line, = ax.plot(x, np.sin(x))

def animate(i):
    line.set_ydata(np.sin(x+i/10.0))  # update the data
    return line,

#Init only required for blitting to give a clean slate.
def init():
    line.set_ydata(np.ma.array(x, mask=True))
    return line,

ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,
    interval=25, blit=True)
plt.show()
Run Code Online (Sandbox Code Playgroud)

实际上它有效.

但是,如果我在函数内部关闭此代码(为了提供更改参数,并避免为每个可能的参数值执行显式文件):

"""
 A simple example of …
Run Code Online (Sandbox Code Playgroud)

python animation matplotlib

10
推荐指数
1
解决办法
4476
查看次数

标签 统计

animation ×1

matplotlib ×1

python ×1