问题
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