Here is my code. I'm using matplotlib.animation.FuncAnimation to create an animation that displays a series of images.
# Function that animates the FAI images
# Grabs the i'th member of nir_images list, plt.imshow's it, then repeats
def build_video(image_list):
fai_image, image_latitudes, image_longitudes, attributes = image_list
time = attributes.at['UTC', 0]
plt.imshow(fai_image, cmap='gist_gray')
plt.title(time.replace('T', ' '))
print(time.replace('T', ' '))
# Set up overall graph
fig=plt.figure(figsize=(20,10))
# Show the images on the right side
plt.subplot(1,2,2)
ani = FuncAnimation(fig, build_video, frames=nir_images, interval=200)
ani.save(os.path.join(output_path, nir_title))
When I ran the code without ani.save(), it seemed like it had the same problem, but it loaded a lot faster so I didn't mind. But now, it's taking over 30 seconds to load a single step of the animation and only gets longer as it completes more steps.
I'm not really sure what I'm doing wrong. I'm just repurposing/reusing code that I was sent that did exactly what I'm trying to do, and it did not have this problem. I did remove a bunch of the code that wasn't necessary for what I'm doing, and I may have accidentally removed something that makes it load faster. Also, that code was run from the Anaconda terminal, while I am running my code by running a cell in a .py file in Spyder. (I'm just a lot more comfortable/familiar with using Spyder instead of running commands from the terminal, when it comes to Python).
Is this the correct way to generate and save an animation?