问题描述
我正在尝试显示一个群体的随机游走并在动画中显示它,但是,FuncAnimation 似乎没有超过第一帧,尽管它正在访问动画函数,因为该帧显示在 spyder 中。
当整个种群 (Npop) 的 Bool=1 或 t 达到 250 时,动画将停止
step_set = (-1,1)
def animate(t):
global NpopCol,NpopA,NpopB,Npop,path,step,step_set,Bool,direction
print(t)
for i in range(0,Npop):
path[i] =step[i]
direction =np.random.choice(step_set,2)
for j in range(0,Npop):
if(Bool[j]==1):
if(path[j][0]==path[i][0])&(path[j][1]==path[i][1]):
Bool[i]=1
##generate a path,moving 1 square right/left,up/down / diagonally
step[i]=step[i]+ direction
NpopCol=[]
for i in range (0,Npop):
if(Bool[i]==1):
NpopCol.append('r')
if(Bool[i]==0) &(i<NpopA) :
NpopCol.append('b')
if(Bool[i]==0) &(i>=NpopA) :
NpopCol.append('g')
if (sum(Bool)==Npop) or t>250:
anim.event_source.stop()
##t=t+1
scat.set_offsets(path)
scat.set_color(NpopCol)
return scat,path
fig,ax=plt.subplots()
scat=plt.scatter(path[:,0],path[:,1],c=NpopCol,s=10)
anim=FuncAnimation(fig,animate,interval=10)
plt.show()
以上是我正在使用的代码,对此问题的任何帮助将不胜感激。
提前致谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)