# -*- coding: utf-8 -*- """ Created on Wed Apr 29 16:27:34 2020 @author: neil """ # This code snippet shows one method of plotting the output from a 2D CA as an animation or movie # it requires importing another module from matplotlib import matplotlib.animation as animation # Create a figure to plot into fig2 = plt.figure() # creates figure to plot the water flow ax2 = fig2.add_subplot(111) ims = [] # 'im' is an empty list, but is a place to save images # you put these two lines inside your loop. After each time step, where you calculate a new # array 'W', which in this case is a x,y grid of where the water is and isn't # These two lines go in your time stepping for loop, after you calculate a new 'W' im = ax2.spy(W,animated=True) # this takes a snapshot of the spy plot of W ims.append([im]) # and adds the snapshot to the growing list of images in 'im' # at the end of your program you show the animation # note that this method of animation works on most systems, but is slow (there are other # faster methods, but they may be harder to setup) im_ani = animation.ArtistAnimation(fig2, ims, interval=500, repeat_delay=1000, blit=True)