Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python matplotlib.pyplot.draw()和matplotlib.pyplot.show()无效_Python_Python 3.x_Numpy_Matplotlib - Fatal编程技术网

Python matplotlib.pyplot.draw()和matplotlib.pyplot.show()无效

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和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)
当我运行这个函数时,我会在最后得到一个包含所有绘图的图形(在
mplot.show()
中也会出现这种情况)

当我在ipython3.1(使用python3.3.5)中从命令行运行它时,我什么也得不到

生成图像时,
mplot.savefig(文件名)
行似乎确实起作用


(这可能是Qt4后端中的错误。)

尝试删除行
matplotlib。使用('Qt4Agg')
。对我有用。也适用于
matplotlib.use('TkAgg')
。因此,这是一个后端问题。有很多方法可以做动画

所以你用
matplotlib.use('Qt4Agg')
尝试了它,但它也不适合你?