在 Matplotlib 中:
- 我可以写
matplotlib.pyplot.cla()为axes.clear(),对象在axes哪里matplotlib.axes.Axes。 - 我可以写成
matplotlib.pyplot.clf(),对象fig.clear()在哪里。figmatplotlib.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方法,它做了很多我不太关注的事情,注意到在交互式后端,这与窗口“销毁”和“删除”事件有关。但我不确定数字和窗口是如何相关的。
也许我在浪费时间甚至考虑这个。