gpt4 book ai didi

python - matplotlib funcAnimation 没有调用传递的函数

转载 作者:行者123 更新时间:2023-11-28 21:07:17 25 4
gpt4 key购买 nike

我正在尝试为机器人的链接设置动画但没有成功。 FuncAnimation 从不调用 animate 函数——从不执行打印语句。任何帮助将不胜感激。我的代码:

def foo():
joints = np.array([robot_kinematics.getJoints(a[0]) for a in path])
# this is [5x9x3]

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
colors = 'brgymcwkk'
lines = [ax.plot([], [], [])[0] for i,c in enumerate(colors)]
pt = ax.plot([], [], [])[0]


def animate(i,lines,pts):
print ('called')
for j,line in enumerate(lines):
line.set_data(joints[i,j,0:2])
line.set_3d_properties(joints[i,j,2])
pts.set_data(joints[i,:,0:2])
pts.set_3d_properties(joints[i,:,2])

return lines,pts

a = animation.FuncAnimation(fig, animate, 25, fargs=(lines,pt),interval=50, blit=False)
plt.show()

foo()

最佳答案

显然,FuncAnimation创建的对象必须赋值给一个全局变量;如果它被分配给一个局部变量,就像我在这里做的那样,什么都不会发生。

关于python - matplotlib funcAnimation 没有调用传递的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41625518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com