我遇到了一个与this question非常相似的问题
但建议的解决方案对我不起作用。在
我已经使用matplotlib动画模块设置了一个动画散点图。当它显示实时时,它工作得很好。我想保存到一个avi文件或类似的东西。我编写的代码没有出错,但它产生的视频只是显示一组空白的轴或黑屏。我已经做了几次检查,数据正在运行和更新,只是没有保存到视频。。。在
我尝试删除this question中建议的“animated=True”和“blit=True”,但这并没有解决问题。在
我已经在下面放置了相关的代码,但可以提供更多,如果需要。有人能建议我该怎么做才能让这个工作正常吗?在
def initAnimation(self):
rs, cfgs = next(self.jumpingDataStreamIterator)
#self.scat = self.axAnimation.scatter(rs[0], rs[1], c=cfgs[0], marker='o')
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)
# Set x and y data...
self.scat.set_offsets(rs[:2,].transpose())
#self.scat = self.axAnimation.scatter(rs[0], rs[1], c=cfgs[0], animated=True)
# Set sizes...
#self.scat._sizes = 300 * abs(data[2])**1.5 + 100
# Set colors..
#self.scat.set_array(cfgs[0])
# We need to return the updated artist for FuncAnimation to draw..
# Note that it expects a sequence of artists, thus the trailing comma.
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)
抱歉耽搁了。我找到了一个解决办法,只需保存大量单独的图像,然后调用ffmpeg将它们链接在一起。这不太理想,但能完成任务。(大班的一部分)
相关问题 更多 >
编程相关推荐