我正在尝试制作一个Line2D集合列表的动画,问题是我正在附加plt.绘图(xx)由于一个if-then-else循环而导致的数组,并且由于我想查看的结果,我需要这种分离。在
如果我把每一个时间步都保存为figure,效果很好,但是对于动画来说就不行了。在
也许你能给我个提示,这是我的代码:
fig2=plt.figure()
for t in range(nt+1):
print('Calculating Timestep '+str(t))
flowfield=u[:,:,t]
for i in (x_indices):
for j in (y_indices):
if flowfield[i,j]==trigs_n:
frame_sensor=plt.plot(i, j,'r*' ,c='r',marker='s',markersize=5,label='1')
elif flowfield[i,j]>=trigs_p:
frame_sensor=plt.plot(i, j, 'g*' ,c='g',marker='s',markersize=5,label='1')
else:
frame_sensor=plt.plot(i, j,'k*',markerfacecolor='white',markeredgecolor='white',marker='s',markersize=5,label='0')
frames_sensor.append([frame_sensor])
anim = animation.ArtistAnimation(fig2,frames_sensor,interval=50,blit=True)
制作线条动画的方法是调用一系列绘图,返回线条对象并使用animate根据新数据更新这些对象。您可以对任意多行执行此操作(if语句没有影响)。作为基于if条件设置多条线动画的最小示例
这将基于当前动画迭代
num
生成数据,如果已经有数据,可以将其用作数组索引。在相关问题 更多 >
编程相关推荐