У меня проблема с симуляцией модели Изинга (не важно).
Моя проблема - это анимация двоичной тепловой карты, где мой массив модулируется функцией:
Этокажется, что моя heatdata
функция вызывается один раз во время анимации:
'''IsingArray Class'''
import numpy as np
import random as rd
import functions as fun
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.animation as animation
class IA:
def __init__(self,long):
self.dim=long
'''Array'''
self.IsingArray=np.ndarray((self.dim,self.dim))
'''Inititate Sites'''
for i in range(self.dim):
for j in range(self.dim):
if rd.random()>=0.5:
self.IsingArray[i,j]=1
else:
self.IsingArray[i,j]=-1
self.raspl=0
self.fig = plt.figure()
def heatdata(self,i):
plt.clf()
FP=sns.heatmap(self.IsingArray, linewidth=0.5,vmin=-1,vmax=1,cmap='bwr')
colorbar=FP.collections[0].colorbar
colorbar.set_ticks([-1,1])
colorbar.set_ticklabels(['DOWN','UP'])`
#replace
self.IsingArray[rd.randint(0,self.dim-1),rd.randint(0,self.dim-1)]=1
self.raspl+=1
def animate(self,nof,safe=False):
animateMe = animation.FuncAnimation(self.fig, self.heatdata(self), nof,interval=100,repeat=False )
if safe==True:
animateMe.save('FieldChange'+'.mp4', fps=20, extra_args=['-vcodec', 'libx264'])
plt.show()
#---------actual programm-----------#
long=5
Ising=IA(long)
print(Ising.raspl)
Ising.animate(10)
print(Ising.raspl)