我需要一些帮助来制作动画情节
我有一个数组x_trj
具有Shape (50,12)
,我想为与2-D Plot中某些列的所有行制作一个动画(因此我可以看到每条线的方向如何)。以下是我的代码:
from matplotlib.animation import FuncAnimation
fig,ax = plt.subplots()
# Plot initial line to fill in as we go
line, = ax.plot([], [], lw=2)
def init():
line.set_data([], [])
return line,
def animate(i):
# Plot resulting trajecotry of car
line.set_xdata(x_trj[i,0:9:4])
line.set_ydata(x_trj[i,1:10:4])
return line,
anim = FuncAnimation(fig, animate, init_func = init, frames=x_trj.shape[0], interval=200) # animation doesn't show up?
但是,动画根本不会显示。我得到的只是一个空的数字。我应该如何解决此问题?我正在Google Colab中编写代码。 动画显示为空的(它具有内置播放按钮):
I have an array x_trj
that has shape (50,12)
, and I would like to make an animation for all the rows corresponding to certain columns in a 2-D plot (so I can see what direction each line is going). Below is my code:
from matplotlib.animation import FuncAnimation
fig,ax = plt.subplots()
# Plot initial line to fill in as we go
line, = ax.plot([], [], lw=2)
def init():
line.set_data([], [])
return line,
def animate(i):
# Plot resulting trajecotry of car
line.set_xdata(x_trj[i,0:9:4])
line.set_ydata(x_trj[i,1:10:4])
return line,
anim = FuncAnimation(fig, animate, init_func = init, frames=x_trj.shape[0], interval=200) # animation doesn't show up?
However, the animation does not show up at all. All I get is an empty figure. How should I fix this issue? I am writing my code in Google colab.
The animation shows up but it's empty (it has a built-in play button):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
我不知道您在
x_traj
中拥有什么值区域会自动显示在我可以看到的区域中。我仅在本地计算机上进行了测试。
最终,您可以在动画期间更改
xlim,ylim
更改可见区域,但这可能不会如您期望的那样。I don't know what values you have in
x_traj
but I had to setxlim
,ylim
to see animation because animation doesn't change visible area automatically and it displays line in area which I can see.I tested it only on local computer.
Eventually you can change
xlim, ylim
during animation to change visible area but this may not look as you expect.