我知道matplotlib中有“ 当前图形”和“ 当前轴”,但是如果我在spyder ipython控制台中逐行运行以下代码,则“ plt.get_fignums ()”始终返回一个空列表。如果每次运行后都清除了“当前图形”和“当前轴”,为什么 plt.gcf()和 plt.gca()仍然返回某些内容?这是否意味着matplotlib在初始化时始终保持空白图形和轴?与matplotlib的“交互模式”有关吗?
import matplotlib.pyplot as plt
plt.figure()
print(plt.get_fignums())
print(plt.gcf(),plt.gca())
更新:我使代码更简单地演示了问题
Python 3.7.3(默认,2019年4月24日,15:29:51)[MSC v.1915 64位(AMD64)] 输入“版权”,“信用”或“许可证”以获取更多信息。
IPython 7.6.1-增强的交互式Python。
In [1]: runfile('xxx.py',wdir='xxx')
[1]
Figure(432x288) AxesSubplot(0.125,0.125;0.775x0.755)
In [2]: print(plt.get_fignums())
...: print(plt.gcf(),plt.gca())
[]
Figure(432x288) AxesSubplot(0.125,0.125;0.775x0.755)
In [6]: plt.figure()
...: print(plt.get_fignums())
[1]
<Figure size 432x288 with 0 Axes>
In [7]: print(plt.get_fignums())
[]