在 pyplot 中保存图形会产生空白 windows
saving figures in pyplot produces blank windows
我正在使用 python 和 matplotlib.pyplot 来制作各种图。
我不是在制作图表 show(),而是使用 matplotlib.pyplot.savefig() 和 matplotlib.pyplot.clf()
保存它们
随着代码的运行,X11 会出现一连串的空白 windows - 我保存的每个图都为 1 - 直到代码完成。
代码有效,我的绘图已按需要保存,但代码 运行 时出现的空白 windows 很烦人。
请问我该如何停止?
编辑:
这发生在我所有的代码上。我想唯一相关的代码是我已经输入的代码:
matplotlib.pyplot.savefig('{0}.png' .format(index))
matplotlib.pyplot.clf()
好的,经过进一步调查,我的问题只有在导入Gpy时才会出现。这是一个显示我的问题的简单示例:
import numpy as np
import GPy
import matplotlib.pyplot as plt
x = np.arange(0,10,1)
for i in range(10):
fig = plt.figure()
plt.plot(x)
plt.savefig('test_{0}.png' .format(i))
plt.clf()
当然现在,我可以删除
导入 Gpy
如果我不需要它,请排队。
我的python版本是2.7.3
很有可能 GPU 以某种方式打开了 matplotlib 交互模式。您可以使用
再次关闭它
plt.ioff()
希望有用
我正在使用 python 和 matplotlib.pyplot 来制作各种图。
我不是在制作图表 show(),而是使用 matplotlib.pyplot.savefig() 和 matplotlib.pyplot.clf()
保存它们随着代码的运行,X11 会出现一连串的空白 windows - 我保存的每个图都为 1 - 直到代码完成。
代码有效,我的绘图已按需要保存,但代码 运行 时出现的空白 windows 很烦人。
请问我该如何停止?
编辑:
这发生在我所有的代码上。我想唯一相关的代码是我已经输入的代码:
matplotlib.pyplot.savefig('{0}.png' .format(index))
matplotlib.pyplot.clf()
好的,经过进一步调查,我的问题只有在导入Gpy时才会出现。这是一个显示我的问题的简单示例:
import numpy as np
import GPy
import matplotlib.pyplot as plt
x = np.arange(0,10,1)
for i in range(10):
fig = plt.figure()
plt.plot(x)
plt.savefig('test_{0}.png' .format(i))
plt.clf()
当然现在,我可以删除 导入 Gpy 如果我不需要它,请排队。
我的python版本是2.7.3
很有可能 GPU 以某种方式打开了 matplotlib 交互模式。您可以使用
再次关闭它plt.ioff()
希望有用