How do I tell matplotlib that I am done with a plot? How do I tell matplotlib that I am done with a plot? python python

How do I tell matplotlib that I am done with a plot?


There is a clear figure command, and it should do it for you:

plt.clf()

If you have multiple subplots in the same figure

plt.cla()

clears the current axes.


You can use figure to create a new plot, for example, or use close after the first plot.


As stated from David Cournapeau, use figure().

import matplotlibimport matplotlib.pyplot as pltimport matplotlib.mlab as mlabplt.figure()x = [1,10]y = [30, 1000]plt.loglog(x, y, basex=10, basey=10, ls="-")plt.savefig("first.ps")plt.figure()x = [10,100]y = [10, 10000]plt.loglog(x, y, basex=10, basey=10, ls="-")plt.savefig("second.ps")

Or subplot(121) / subplot(122) for the same plot, different position.

import matplotlibimport matplotlib.pyplot as pltimport matplotlib.mlab as mlabplt.subplot(121)x = [1,10]y = [30, 1000]plt.loglog(x, y, basex=10, basey=10, ls="-")plt.subplot(122)x = [10,100]y = [10, 10000]plt.loglog(x, y, basex=10, basey=10, ls="-")plt.savefig("second.ps")