matplotlib动画产生空白 [英] matplotlib animation produces a blank
本文介绍了matplotlib动画产生空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一堆要转换为动画的PNG.我为此使用matplotlib.我可以在屏幕上显示最终的动画,一切看起来都很好.但是保存的MP4只是空白.我的意思是我可以玩,但是它只显示了一个白色的,没有功能的窗口.有什么想法我做错了吗?这是代码:
I have a bunch of PNGs that I want to turn into an animation. I use matplotlib for this. I can display the resulting animation on the screen and everything looks fine. But the saved MP4 is just a blank. I mean I can play it, but it just shows a white, featureless window. Any ideas what I'm doing wrong? Here's the code:
import matplotlib
matplotlib.use('TKAgg')
import pylab as pyl
import matplotlib.pyplot as pplt
import matplotlib.image as mplimg
import matplotlib.animation as mplanim
myimages = []
for k in range(1,100):
fname = "data{0:03d}.png".format(k)
img = mplimg.imread(fname)
imgplot = pplt.imshow(img)
myimages.append([imgplot])
fig = pyl.figure()
myanim = mplanim.ArtistAnimation(fig, myimages, interval=20,
blit=True, repeat_delay=1000)
myanim.save("anim.mp4", fps=10)
pyl.show()
更新:在导入解决问题之后,立即将fig = pyl.figure()
移至代码顶部.如果有人知道为什么,请随时告诉!谢谢.
UPDATE: Moving fig = pyl.figure()
to the top of the code, right after the imports solves the problem. If anyone knows why, feel free to tell! Thanks.
推荐答案
更正此行:
myimages.append([imgplot])
进入:
myimages.append(imgplot)
看看是否可行.
这篇关于matplotlib动画产生空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文