I want to create a plot, perhaps abandon it, then create another plot.
import matplotlib.pyplot as plt
plt.plot(xxx,yyy, ...)
if certain_conditions:
return or otherwise get out of here
plt.show()
...sometime later, someplace far away...
# looking for incantation to make gone of the existing unshown plot
plt.plot(abc,def, ...)
plt.show()
These pieces of code are actually far apart, in different objects or modules, whatever. When the first plot is abandoned, the show() in the second chunk of code will show me more than what is desired; I just want to see abc vs. def plotted. I’m sure this is simple but I’m not finding it – what magic incantation do I want before starting the 2nd plot?
There are a bunch of ways to do this, the ‘best’ is to move to using the OO interface instead of the state machine interface.
If you don’t want to keep any figures you can do
which will close all existing figures. If you just want to close the current figure, you can do
If you do
you can create additional figures and close them with