What I usually do is to clear the axis (using cla() only) right after creating or accessing it (either with figure() or subplot() or similar magic):

from pylab import *

fig = figure(num=1)

for example in range(5):
  cla()
  plot(rand(100))
  savefig('test-%d.png'%example)



-------- Original Message --------
Subject: [Matplotlib-users] Clearing A Figure (I Know That This Has Been Posted Before But I Does Not Work For Me)
Date:   Tue, 25 May 2010 02:08:42 -0700 (PDT)
From:   Thistleryver <mhar...@ec.auckland.ac.nz>
To:     matplotlib-users@lists.sourceforge.net



I am attempting to run a lot of tests automatically and generate a graph for
each one.  However, at the moment, the previous graph remains on the figure
and the next plot is drawn over it.

I have read extensively the documentation and I have tried a whole lot of
different commands but to no avail.  In the previous post it said to use
pylab.clf() which is exactly what I've been trying to use.

So far I have used pylab.cla(), pylab.clf() and pylab.close() although I
believe that this only closes an open figure window.  I have no idea why it
is not working now especially since it would appear that my question had
already been answered in both the documentation and the forums.

I am using Python 2.6.4 on Ubuntu Linux.

Here is the relevant code I am using:
        pylab.plot(xAxis, TrainingPoints, 'b-')

        pylab.plot(xAxis, TestPoints, 'r-')

        pylab.xlabel('Epochs')

        pylab.ylabel('Sum Squared Error')

        pylab.title('Plot of Iris Training Errors')

        outfilename = str(int(LEARNING_RATE)) + ".png"
        print outfilename
        pylab.ylim(ymin=0)
        pylab.savefig(outfilename)
        pylab.cla()
        pylab.clf()

I really hope one of you can spot an error otherwise I am completely stuck.
--
View this message in context: 
http://old.nabble.com/Clearing-A-Figure-%28I-Know-That-This-Has-Been-Posted-Before-But-I-Does-Not-Work-For-Me%29-tp28665976p28665976.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


------------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

------------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to