的文档matplotlib.animation.FuncAnimation说:
init_func : [...] 该函数将在第一帧之前调用一次。
但每当我使用 时FuncAnimation,都会init_func被多次调用。您可以通过向 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)
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():
# ---> Adding a print …Run Code Online (Sandbox Code Playgroud) 在我最近的一个问题中,我引用了Jake Vanderplas的一些代码.可以找到以下代码:
from matplotlib import pyplot as plt
from matplotlib import animation
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(0, 100))
line, = plt.plot([], [])
def init():
line.set_data([], [])
return line,
def animate(i):
line.set_data([0, 2], [0,i])
return line,
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=100, interval=20, blit=True)
plt.show()
Run Code Online (Sandbox Code Playgroud)
在initor animate函数中,返回"value"是line,(用逗号).
问题:返回"值"是否会有line(whitout逗号)?
谢谢