matplotlib的FuncAnimation使用的初始化和动画函数有哪些要求?

时间:2014-12-23 16:04:08

标签: python animation matplotlib

matplotlib's FuncAnimation的初始化(init_func)和动画(func)参数有哪些要求?

all the examples我可以发现,这两个函数似乎总是依赖于使用(1)全局matplotlib实例,(2)与绘制的数字相关联, (3)通过实例方法专门改变,(4)由每个函数返回。例如:

fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))   # (1)(2)
line, = ax.plot([], [], lw=2)              # (1)(2)

# for init_func argument
def init():
    global line                            # (1)
    line.set_data([], [])                  # (3)
    return line,                           # (4)

# for func argument
def animate(i):
    global line                            # (1)
    x = np.linspace(0, 2, 1000)
    y = np.sin(2 * np.pi * (x - 0.01 * i))
    line.set_data(x, y)                    # (3)
    return line,                           # (4)

动画是否需要所有这些元素才能工作,或者我可以在两个函数中编写任何更改图形元素(fig)的代码吗?

如果需要这些元素,我将如何编写动画函数来更改(添加,删除,重新定位和调整大小)几个注释和行,例如

 ax.annotate("Some text 1", (x1, y1), ... )
 ax.annotate("Some text 1", (x1, y1), ... )
 ...
 ax.annotate("Some text N", (xN, yN), ... )
 ...
 ax.plot(... )
 ax.plot(... )

0 个答案:

没有答案