Updating one “pixel” with imshow

╄→гoц情女王★ 提交于 2019-12-25 01:09:05

问题


I am simulating an IsingModel with the Metropolis-Algorithm in Fortran and want to visualize the steps with python as a movie. I have a 100x100 grid with values from {-1,1} and performe about 1_000_000 steps/changes on the grid.

I thought i could plot/animate each step with the matplotlib function pyplot.imshow as i needed some snapshots/images also. However i cant find an option to just update the "pixel" which was changed the last step. And set_array(...) is reaaaallllyyy slow... Is there a quick solution which i don't see or do i have to pick another library?

def init():
    global lattice
    lattice=ff.read_record('({},{})i1'.format(N,N))
    im.set_data(lattice)
    return [im]

# animation function.  This is called sequentially
def animate(i):
    change=np.array(ff.read_record('i1','i1')).ravel()
    if(change[0]!=-1):
        lattice[change[0],change[1]]=-1*lattice[change[0],change[1]]

    im.set_array(lattice)
    return [im]

anim = animation.FuncAnimation(fig, animate,frames=10000 interval=10, init_func=init, blit=True)
anim.save('basic_animation.mp4', fps=30)

来源:https://stackoverflow.com/questions/56960098/updating-one-pixel-with-imshow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!