I have a very similar problem to this question
but the proposed solution does not work for me.
I created an animated scatter plot using the matplotlib animation module. This works great when displayed in real time. I would like to save it in an avi file or something like that. The code I wrote for this does not throw an error, but the created video just shows a blank set of axes or a black screen. I performed a few checks, and the data starts up, and the number is updated, and it just isn't saved on the video ...
I tried to remove "animated = True" and "blit = True" as suggested in this question , but this did not help to solve the problem.
I have posted the appropriate code below, but can provide more if necessary. Can anyone suggest what I have to do for this to work?
def initAnimation(self):
rs, cfgs = next(self.jumpingDataStreamIterator)
self.scat = self.axAnimation.scatter(rs[0], rs[1], c=cfgs[0], marker='o', animated=True)
return self.scat,
def updateAnimation(self, i):
"""Update the scatter plot."""
rs, cfgs = next(self.jumpingDataStreamIterator)
self.scat.set_offsets(rs[:2,].transpose())
matplotlib.pyplot.draw()
return self.scat,
def animate2d(self, steps=None, showEvery=50, size = 25):
self.figAnimation, self.axAnimation = matplotlib.pyplot.subplots()
self.axAnimation.set_aspect("equal")
self.axAnimation.axis([-size, size, -size, size])
self.jumpingDataStreamIterator = self.jumpingDataStream(showEvery)
self.univeseAnimation = matplotlib.animation.FuncAnimation(self.figAnimation,
self.updateAnimation, init_func=self.initAnimation,
blit=True)
matplotlib.pyplot.show()
def animate2dVideo(self,fileName=None, steps=10000, showEvery=50, size=25):
self.figAnimation, self.axAnimation = matplotlib.pyplot.subplots()
self.axAnimation.set_aspect("equal")
self.axAnimation.axis([-size, size, -size, size])
self.Writer = matplotlib.animation.writers['ffmpeg']
self.writer = self.Writer(fps=1, metadata=dict(artist='Universe Simulation'))
self.jumpingDataStreamIterator = self.jumpingDataStream(showEvery)
self.universeAnimation = matplotlib.animation.FuncAnimation(self.figAnimation,
self.updateAnimation, scipy.arange(1, 25), init_func=self.initAnimation)
self.universeAnimation.save('C:/universeAnimation.mp4', writer = self.writer)