In MatPlotLib, I can use:
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. 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
fig1.clear()
will clear the figure stored in fig1.
Of course you can also directly use the call to plt.figure() to clear that figure,
plt.figure(1).clear()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With