清除MatPlotLib中的特定数字

时间:2017-05-19 16:45:48

标签: python matplotlib

在MatPlotLib中,我可以使用:

plt.gcf().clear()

清除当前数字的内容。

但是假设我有两个数字,用:

创建
fig1 = plt.figure(1)
fig2 = plt.figure(2)

如何根据数字清除特定数字?

1 个答案:

答案 0 :(得分:3)

.clear()是图类的一种方法。如果您通过matplotlib.figure.Figure或通过您存储的变量获取plt.gcf()的实例,则无关紧要。因此

fig1.clear()

将清除fig1中存储的数字。

当然,你也可以直接使用plt.figure()来调用这个数字,

plt.figure(1).clear()