I'm in doubt about what is the difference among the codes below. I'm using matplotlib's animation class to render numpy's arrays. In the atualizaMundo()
function, if I use mundo[:] = new_mundo[:]
it works just fine, but if I use mundo=new_mundo
the arrays get equal but the animation doesn't work. What is the difference here?
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
ON = 255
OFF = 0
def criaMundo(N):
return(np.random.choice([ON,OFF],N*N,p=[0.5,0.5]).reshape(N,N))
def atualizaMundo(frameNum,N,mundo,img):
new_mundo = np.random.choice([ON,OFF],N*N,p=[0.5,0.5]).reshape(N,N)
img.set_data(mundo)
mundo[:]=new_mundo[:]
#mundo=new_mundo
return(img,)
def main():
try:
N = 4
mundo = criaMundo(N)
print(mundo)
fig1,ax = plt.subplots()
img = ax.imshow(mundo)
animacao = animation.FuncAnimation(fig1, atualizaMundo, fargs=(N,mundo,img,), blit=True)
plt.show()
except Exception as ex:
pass
if __name__ == '__main__':
try:
main()
except Exception as fk:
pass