0

I have a script which uses the FuncAnimation routines in a loop to generate a lot of different animations which are saved in various directories. I'm working in Spyder, and every time an animation is generated, a .PNG image is displayed in the console.

Is there any way to NOT display the .PNG file with every animation? I'd like to turn off this image, since they will fill up my console in a long loop. When generating simple plots, it's easy to not display the image by just not calling plt.show. For animations, plt.show is called isn't called at all and the image still displays.

You can see that a .PNG image generated in the basic example:

import numpy as np
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.animation as animation

def update_line(num, data, line):
    line.set_data(data[..., :num])
    return line,

# Fixing random state for reproducibility
np.random.seed(19680801)

# Set up formatting for the movie files
Writer = animation.writers['ffmpeg']
writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800)

fig = plt.figure()
data = np.random.rand(2, 25)
l, = plt.plot([], [], 'r-')
plt.xlim(0, 1)
plt.ylim(0, 1)
line_ani = animation.FuncAnimation(fig, update_line, 25, fargs=(data, l),
                                   interval=50, blit=True)
line_ani.save('lines.mp4', writer=writer)
BenjaminDSmith
  • 170
  • 1
  • 9

1 Answers1

1

The .PNG image associated with the animation can be effectively hidden by calling plt.close(fig) after the animation is saved. This answer was inspired by a response by Demis to a similar question asking about simple plots instead of animations.

BenjaminDSmith
  • 170
  • 1
  • 9