Python matplotlib.pyplot.draw()和matplotlib.pyplot.show()无效
在过去,我可以使用matplotlib和for循环制作简单的动画,但这已经有一段时间不起作用了 标准答案是必须打开交互模式和/或使用Python matplotlib.pyplot.draw()和matplotlib.pyplot.show()无效,python,python-3.x,numpy,matplotlib,Python,Python 3.x,Numpy,Matplotlib,在过去,我可以使用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
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)
当我运行这个函数时,我会在最后得到一个包含所有绘图的图形(在mplot.show()
中也会出现这种情况)
当我在ipython3.1(使用python3.3.5)中从命令行运行它时,我什么也得不到
生成图像时,mplot.savefig(文件名)
行似乎确实起作用
(这可能是Qt4后端中的错误。)尝试删除行
matplotlib。使用('Qt4Agg')
。对我有用。也适用于matplotlib.use('TkAgg')
。因此,这是一个后端问题。有很多方法可以做动画 所以你用matplotlib.use('Qt4Agg')
尝试了它,但它也不适合你?