简体   繁体   English

清除MatPlotLib中的特定图形

[英]Clearing a specific figure in MatPlotLib

In MatPlotLib, I can use: 在MatPlotLib中,我可以使用:

plt.gcf().clear()

To clear the contents of the current figure. 清除当前图形的内容。

But suppose I have two figures, created with: 但是假设我有两个数字,分别是:

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

How can I clear a specific figure based on its number? 如何根据数字清除特定数字?

.clear() is a method of the figure class. .clear()是图形类的方法。 It doesn't matter if you obtain an instance of matplotlib.figure.Figure via plt.gcf() or via the variable you store it in. Therefore 通过plt.gcf()或通过将其存储在其中的变量来获取matplotlib.figure.Figure的实例都没有关系。

fig1.clear()

will clear the figure stored in fig1 . 将清除存储在图1中的fig1

Of course you can also directly use the call to plt.figure() to clear that figure, 当然,您也可以直接使用对plt.figure()的调用来清除该图形,

plt.figure(1).clear()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM