matplotlib funcanimation仅显示一个框架
我正在尝试使用funcanimation
模块进行动画,但我的代码只会产生一个帧。看起来它更新了正确的东西(k
),并继续使用适量的框架的动画,但是每个帧显示了第一个图像,其中k = 0。
def plotheatmap(u_k, k):
# Clear the current plot figure
plt.clf()
plt.title(f"Temperature at t = {k*dt:.3f} unit time")
plt.xlabel("x")
plt.ylabel("y")
# This is to plot u_k (u at time-step k)
plt.pcolormesh(u_k, cmap=plt.cm.jet, vmin=0, vmax=4)
plt.colorbar()
def animate(k):
plotheatmap(convert(U)[k], k)
anim = animation.FuncAnimation(plt.figure(), animate, interval=200, frames=M+1)
I am trying to do an animation using the FuncAnimation
module but my code only produces one frame. It looks like that it update the right thing (k
) and it go on with the animation for the right amount of frames, but every frame shows the first image with k=0.
def plotheatmap(u_k, k):
# Clear the current plot figure
plt.clf()
plt.title(f"Temperature at t = {k*dt:.3f} unit time")
plt.xlabel("x")
plt.ylabel("y")
# This is to plot u_k (u at time-step k)
plt.pcolormesh(u_k, cmap=plt.cm.jet, vmin=0, vmax=4)
plt.colorbar()
def animate(k):
plotheatmap(convert(U)[k], k)
anim = animation.FuncAnimation(plt.figure(), animate, interval=200, frames=M+1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您没有提供可再现的示例,因此我将生成随机数据,并且您将其适应您的情况。
Since you didn't provide a reproducible example, I'm going to generate random data, and you will adapt it to your case.