在过去,我可以用matplotlib和for循环来制作简单的动画,但是这已经有一段时间不起作用了。你知道吗
标准答案是必须打开交互模式和/或使用matplotlib.pyplot.draw()
强制重画。下面是我最简单的工作示例:
import numpy as np
import matplotlib
matplotlib.use('Qt4Agg')
import matplotlib.pyplot as mplot
mplot.ion()
fig = mplot.figure(1)
ax = fig.add_subplot(111)
for ii in np.arange(0,10):
x = 200*np.random.rand(30)
ax.plot(x)
mplot.draw()
filename = ("img_%d.png" % ii)
mplot.savefig(filename)
当我在Interactive Python Editor中运行这个程序时,我会在最后得到一个包含所有绘图的图(在mplot.show()
中也会出现这种情况)
当我在ipython3.1(使用python3.3.5)中从命令行运行它时,我什么都没有得到。你知道吗
生成图像时,mplot.savefig(filename)
行似乎确实起作用。你知道吗
(这可能是Qt4后端的一个bug。)
尝试删除行
matplotlib.use('Qt4Agg')
。对我有用。也适用于matplotlib.use('TkAgg')
。所以这是一个后端问题。有another way做动画。你知道吗相关问题 更多 >
编程相关推荐