在Matplotlib:Matplotlib窗口类? OO相当于matplotlib.pyplot.close()?
- 我可以写
matplotlib.pyplot.cla()
作为axes.clear()
,其中axes
是matplotlib.axes.Axes
对象。 - 我可以写
matplotlib.pyplot.clf()
作为fig.clear()
,其中fig
是matplotlib.figure.Figure
对象。
然后有matplotlib.pyplot.close()
。这关闭了一个窗口。这个窗口是否对应于任何类别?有x.close()
相当于matplotlib.pyplot.close()
,但在一个更加面向对象的风格?
为matplotlib.pyplot.close()
我的版本的源代码如下:
if len(args)==0:
figManager = _pylab_helpers.Gcf.get_active()
if figManager is None: return
else:
_pylab_helpers.Gcf.destroy(figManager.num)
elif len(args)==1:
arg = args[0]
if arg=='all':
_pylab_helpers.Gcf.destroy_all()
elif isinstance(arg, int):
_pylab_helpers.Gcf.destroy(arg)
elif is_string_like(arg):
allLabels = get_figlabels()
if arg in allLabels:
num = get_fignums()[allLabels.index(arg)]
_pylab_helpers.Gcf.destroy(num)
elif isinstance(arg, Figure):
_pylab_helpers.Gcf.destroy_fig(arg)
else:
raise TypeError('Unrecognized argument type %s to close'%type(arg))
else:
raise TypeError('close takes 0 or 1 arguments')
所以,这似乎是基于静态方法的 matplotlib._pylab_helpers.Gcf.destroy
它做了各种各样的事情,我不知道情况,并指出, 在交互式后端中,这被绑定到窗口“销毁”和“删除”事件。但我不确定数字和窗口是如何相关的。
也许我在浪费我的时间,甚至想到这个。
我可以提供的最好建议:不要害怕看pyplot源代码。我会在接下来的几天发布一个答案,如果其他人(或者你甚至)不会打败我:-) HTH – pelson 2013-02-13 20:07:06