Re: [Matplotlib-users] Clearing A Figure (I Know That This Has Been Posted Before But I Does Not Work For Me)
w/o seeing the entire code it is difficult to diagnose. Nothing looks wrong with your code. However, for full control I suggest you use the API; see examples at http://matplotlib.sourceforge.net/examples/api/index.html and take a look at the artist tutorial at http://matplotlib.sourceforge.net/users/artists.html. Thank you. The tutorial was very helpful. For a moment I thought I might have found the answer with the lines.remove() function but alas, it did not make a difference yet again. :( I am starting to feel that this is a problem with my setup rather than my code. I may have to try this on someone else's computer. In a nutshell fig = plt.figure() ax = fig.add_subplot(111) for param in myparams: fig.clf() ax.plot(something_with(param)) ax.set_ylabel('Sum Squared Error') ax.set_title('Plot of Iris Training Errors') ax.set_ylim(ymin=0) outfilename = '%d.png'%param fig.savefig(outfilename) This is almost exactly the same as something else I have tried but this is all to no avail. I have posted all of my code at http://code-bin.homedns.org/653 if anyone has time to look at it. -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- 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-tp28665976p28678426.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
Re: [Matplotlib-users] Clearing A Figure (I Know That This Has Been Posted Before But I Does Not Work For Me)
On Tue, May 25, 2010 at 4:08 AM, Thistleryver mhar...@ec.auckland.ac.nz wrote: 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() w/o seeing the entire code it is difficult to diagnose. Nothing looks wrong with your code. However, for full control I suggest you use the API; see examples at http://matplotlib.sourceforge.net/examples/api/index.html and take a look at the artist tutorial at http://matplotlib.sourceforge.net/users/artists.html. In a nutshell fig = plt.figure() ax = fig.add_subplot(111) for param in myparams: fig.clf() ax.plot(something_with(param)) ax.set_ylabel('Sum Squared Error') ax.set_title('Plot of Iris Training Errors') ax.set_ylim(ymin=0) outfilename = '%d.png'%param fig.savefig(outfilename) -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] clearing a figure
Christopher Barker wrote: Eric Firing wrote: Even without the automatic-redraw difference, the OO interface requires more typing, and more mental record-keeping, than the pylab interface. Yes, but I don't think that's inherent in an OO interface, it's just that the quickie utilities are missing from the current OO interface. oh, and it's not mental record keeping -- it's explicit record keeping, which is why I like it: F1 = OOlab.Figure() F2 = OOlab.Figure() Isn't that better than trying to remember which is the current figure? Typing plot(x,y) is easier to do and remember than creating a figure, adding axes, and then typing ax1.plot(x,y). Why couldn't plot(x,y) create and return a figure object? Or an axis object? -- I haven't thought it out too much yet. Chris: In the pylab interface, figure() returns a figure instance and plot(x,y) returns a list of Line2d instances. from pylab import * l = plot([1,2,3]) l [matplotlib.lines.Line2D instance at 0x3dcf738] f = figure() f matplotlib.figure.Figure instance at 0x3dcf710 I guess I agree with Eric, I don't really see much benefit for the OO interface for interactive use. -Jeff -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX: (303)497-6449 NOAA/OAR/PSD R/PSD1Email : [EMAIL PROTECTED] 325 BroadwayOffice : Skaggs Research Cntr 1D-124 Boulder, CO, USA 80303-3328 Web: http://tinyurl.com/5telg - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] clearing a figure
Eric Firing wrote: I think this may be a slippery slope. The problem is that for it to work well, there has to be a clear distinction between methods that are endpoints, requiring a redraw, and methods that will be used by other methods. For example, errorbar makes multiple calls to plot, vline, etc. I agree -- I don't mind a call to Draw() or something now and then. maybe I can put them in my hypothetical OOlab (see prev. msg.) some day, so that there are a few calls that do the draw, but not every call to plot(). by including an additional kwarg (redraw=False), That's the question -- in my wxPython FloatCanvas, I decided that NOTHING redraws, and you have to make a call to Draw(0 to get a re-draw. In fact, that won't even work if the Canvas thinks nothing has changed, so you sometimes need to call Draw(force=True). In that case, I was optimizing for fast drawing of lots of stuff, and for embedding in a program -- not interactive use. I do like the default redraw of False that can be overridden -- but how many places will that have to be added to the code? -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception [EMAIL PROTECTED] - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] clearing a figure
Jeff Whitaker wrote: Chris: In the pylab interface, figure() returns a figure instance and plot(x,y) returns a list of Line2d instances. yes, but it's the axis instance that you are most likely to need! - Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception [EMAIL PROTECTED] - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] clearing a figure
Christopher Barker wrote: Jeff Whitaker wrote: Chris: In the pylab interface, figure() returns a figure instance and plot(x,y) returns a list of Line2d instances. yes, but it's the axis instance that you are most likely to need! - Chris Chris: Never noticed this before, but apparently the parent axes instance is attached to the Line2d instance: from pylab import * l = plot([1,2,3]) l[0].axes matplotlib.axes.Subplot instance at 0x3240e90 -Jeff -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX: (303)497-6449 NOAA/OAR/PSD R/PSD1Email : [EMAIL PROTECTED] 325 BroadwayOffice : Skaggs Research Cntr 1D-124 Boulder, CO, USA 80303-3328 Web: http://tinyurl.com/5telg - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] clearing a figure
Jeff Whitaker wrote: Chris: Never noticed this before, but apparently the parent axes instance is attached to the Line2d instance: from pylab import * l = plot([1,2,3]) l[0].axes matplotlib.axes.Subplot instance at 0x3240e90 cool! That could be handy. thanks, -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception [EMAIL PROTECTED] - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] clearing a figure
Hi, With the exception of ipython -pylab, noone is forcing you to import *. And on the subject, Fernando, perhaps we should support a pylab mode in ipython which doesn't dump the pylab namespace (or maybe just dumps the required figure, show, close, nx), but does the interactive backend stuff. In the meantime, I did the following to my local dev copy of IPython: Instead of the existing import... viq exec into user namespace, I do: import pylab as P import numpy as N import matplotlib as M It would be nice if controlling this type of thing was configurable. --b - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] clearing a figure
Christopher == Christopher Barker [EMAIL PROTECTED] writes: Christopher F1 = OOlab.Figure() F2 = OOlab.Figure() We have this: fig1 = pylab.figure() fig2 = pylab.figure() ax1 = fig.add_subplot(111) line, = ax1.plot([1,2,3]) line.set_color('green') ax1.set_title('hi mom') Yes, it would be nice to be able to do ax1.title = 'hi mom' but other than that pretty much everything you describe already exists. Instead of thinking about OOlab, which mostly already exists, I think it's more useful to focus on a few shortcuts which will make OO use as easy as pylab. It is already -- I pretty much use the OO interface exclusively in all my work. All my scripts start with from pylab import figure, close, show, nx and that's all, and it works fine. One helpful tip: the children point to their parents, so expanding on Jeff's point about the line containing a pointer to the axes it lives in, you can also reference the figure and canvas as upstream containers line.axes.figure.canvas.draw() for example. Christopher Why couldn't plot(x,y) create and return a figure Christopher object? Or an axis object? -- I haven't thought it Christopher out too much yet. Because it returns a line object. But I do think it is a design limitation to plot make an axes method. For interactive use, I really don't see any advantage to an OO Christopher interface. Christopher Well, for *just* interactive use, I agree, but I see Christopher some very large advantages to an OO style for Christopher embedding in programs and larger projects. Sure, all programmers agree with that. For scripts and apps, the OO interface is clearly superior. Teachers teaching students who are new to programming, however, are adamant that the pylab/proceedural interface is crucial to get them to adopt python over matlab, and I trust them. And for interactive quick-and-dirty minimize-the-typing work, the current figure, current axes approach is quite handy. Christopher As handy as it is to have a command line to play Christopher with, if I'm writing more than four or five lines Christopher (and I usually am!), I'm happier putting them in a Christopher file and running them as a script. Even in that case, Christopher I don't mind a little extra typing. Christopher What I'm envisioning for OOlab is a set of utility Christopher functions that do make some of the pylab stuff easy Christopher -- not well thought out yet, but something like: It's all there with the exception of GUI window management, and you might as well use pylab for that. That saves you a lot of boilerplate. Christopher F = ooLab.figure(1) # I often need to plot more than Christopher one figure anyway, so I don't mind having to type Christopher that. Christopher ax = F.plot(x,y) # there could be this and subplot Well, this breaks the whole concept of multiple axes, though one could have a helper function that assumes subplot(111) ... But explicit is better than implicit so may as well instantiate the Axes with fig.add_subplot... Christopher ax.set_title = A title for the plot # or better Christopher yet: ax.title = A title for the plot # I'd like to Christopher see more properties in MPL too! Agreed. Christopher ax.grid(True) . . . Exists... Christopher Note that some of this comes from my love of Christopher namespaces -- I really don't like import* -- the Christopher way that can work is using more OO, so you don't need Christopher to type the module name everywhere. With the exception of ipython -pylab, noone is forcing you to import *. And on the subject, Fernando, perhaps we should support a pylab mode in ipython which doesn't dump the pylab namespace (or maybe just dumps the required figure, show, close, nx), but does the interactive backend stuff. Christopher I don't see much advantage to keeping the idea of a Christopher current figure or current axis -- it's just not Christopher that hard to keep a reference. Maybe it does help for Christopher quickie command line stuff, but I think for even Christopher quickie scripts, it's clearer to name your axes, etc. Agreed. I should rewrite all the examples and move the existing examples into a matlab-like dir. The examples would all start with the minimal import of figure, show, nx and close. Christopher However, the proof is in the pudding -- what needs to Christopher be done is for someone to sit down and start using Christopher MPL in interactive/quickie script use without pylab, Christopher and write something for OOlab whenever something is Christopher harder to do than it should be. Then we'll see how it Christopher works out. No, one should just use pylab for figure creation and destruction and add convenience methods to shorten some calls if needed, just as we did when we added fig.savefig as a shorthad for
Re: [Matplotlib-users] clearing a figure
Belinda - The hold state is on by default when you use pylab. To clear a figure you use clf(). Here's a brief example: from pylab import * figure() # Not really needed, you could have typed plot right away, but here you can set some nice features like the size plot([1,2,3]) plot([2,1,2]) # Will appear on same figure clf() # Clears entire figure (back to what you had with figure() ) Mark Message: 10 Date: Tue, 09 Jan 2007 19:50:15 -0800 From: belinda thom [EMAIL PROTECTED] Subject: [Matplotlib-users] clearing a figure To: matplotlib-users matplotlib-users@lists.sourceforge.net Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Hello, I'm a new matplotlib user, coming from the Matlab end. Is there a standard way to create a figure (here I'd like the equivalent of matlab's hold on, so I can draw multiple things) and then clear the figure (so the drawing goes away) so I can repeat the process again? The commands to plot that I'll be using are fairly simple line commands. -- - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users End of Matplotlib-users Digest, Vol 8, Issue 13 *** - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] clearing a figure
Eric Firing wrote: This is the big difference between most pylab functions and the corresponding axes or figure methods that they wrap: the pylab functions automatically take care of redrawing the figure if you are in an interactive mode. Now I feel bad -- I think I encouraged Belinda to work with the OO interface, because I think it's the better way to go, and, in particular, translates better to putting MPL code in larger programs. However, it is the case that there is a lot of stuff in pylab that makes it easier to use MPL in interactive mode. I kind of think that's a shame. I don't think that there is any reason that an OO interface is less suited to interactive mode. I've thought for a while that I'd love to write a OOlab module -- that is, an object oriented interface to matplotlib that is well suited to interactive use. However, 1) who know when I'll get around to it, and I haven't yet because I hardly ever do much interactively anyway (I didn't with Matlab, either). 2) this is an example of how it's hard to do -- a method like Figure.Clear() clearly belongs just where it is in an OO framework. Would it be possible for all those OO drawing methods to be able to query an interactive property somewhere? Does it live only in pylab now? -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception [EMAIL PROTECTED] - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] clearing a figure
Christopher == Christopher Barker [EMAIL PROTECTED] writes: Christopher However, it is the case that there is a lot of stuff Christopher in pylab that makes it easier to use MPL in Christopher interactive mode. I kind of think that's a shame. I Christopher don't think that there is any reason that an OO Christopher interface is less suited to interactive mode. It's currently implemented in pylab but could be moved up to the OO layer by doing something like class Axes: def plot(self, *args, **kwargs): ...plot something if rcParams['interactive']: self.figure.canvas.draw() or by providing some autowrapper facility to automate this. Probably could be done elegantly with decorators, but we can't use decorators yet... Or OO users can just call fig.canvas.draw() themselves when they want to draw JDH - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] clearing a figure
John Hunter wrote: It's currently implemented in pylab but could be moved up to the OO layer by doing something like class Axes: def plot(self, *args, **kwargs): ...plot something if rcParams['interactive']: self.figure.canvas.draw() or by providing some autowrapper facility to automate this. That could work -- and/or subclass the key classes, and wrap their plot, etc. methods. hmmm.. Or OO users can just call fig.canvas.draw() themselves when they want to draw Well, yes, but the point I'm making is that it should be just as easy to use interactively -- that's a bit too much code to want to type at the command line. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception [EMAIL PROTECTED] - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] clearing a figure
Christopher Barker wrote: Eric Firing wrote: This is the big difference between most pylab functions and the corresponding axes or figure methods that they wrap: the pylab functions automatically take care of redrawing the figure if you are in an interactive mode. Now I feel bad -- I think I encouraged Belinda to work with the OO interface, because I think it's the better way to go, and, in particular, translates better to putting MPL code in larger programs. However, it is the case that there is a lot of stuff in pylab that makes it easier to use MPL in interactive mode. I kind of think that's a shame. I don't think that there is any reason that an OO interface is less suited to interactive mode. Even without the automatic-redraw difference, the OO interface requires more typing, and more mental record-keeping, than the pylab interface. Typing plot(x,y) is easier to do and remember than creating a figure, adding axes, and then typing ax1.plot(x,y). For interactive use, I really don't see any advantage to an OO interface. What advantage do you see? Eric - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] clearing a figure
John Hunter wrote: Christopher == Christopher Barker [EMAIL PROTECTED] writes: Christopher However, it is the case that there is a lot of stuff Christopher in pylab that makes it easier to use MPL in Christopher interactive mode. I kind of think that's a shame. I Christopher don't think that there is any reason that an OO Christopher interface is less suited to interactive mode. It's currently implemented in pylab but could be moved up to the OO layer by doing something like class Axes: def plot(self, *args, **kwargs): ...plot something if rcParams['interactive']: self.figure.canvas.draw() I think this may be a slippery slope. The problem is that for it to work well, there has to be a clear distinction between methods that are endpoints, requiring a redraw, and methods that will be used by other methods. For example, errorbar makes multiple calls to plot, vline, etc. Even in interactive mode, we don't want redraws after each of those calls, only after the errorbar call itself. This could be handled by including an additional kwarg (redraw=False), or by requiring that methods like errorbar use only lower-level primitives, but either way, complexity increases. Eric or by providing some autowrapper facility to automate this. Probably could be done elegantly with decorators, but we can't use decorators yet... Or OO users can just call fig.canvas.draw() themselves when they want to draw JDH - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] clearing a figure
One of the reasons I'm confused is b/c when I poked around, I found a clear method: help(pylab.gcf().clear) Help on method clear in module matplotlib.figure: clear(self) method of matplotlib.figure.Figure instance Clear the figure but when I execute this on my open figure: pylab.gcf().clear() nothing happens; the figure's still displaying whatever was already on it. So far, the only thing I've found that works is to call plot differently when its time to clear the figure (pass hold=False). Subsequent calls to plot (w/o this option) keep adding to, which is great. Is passing a hold=False arg to a drawing command the preferred way to clear a figure, or is clear() not working properly? Many thanks, --b On Jan 9, 2007, at 7:50 PM, belinda thom wrote: Hello, I'm a new matplotlib user, coming from the Matlab end. Is there a standard way to create a figure (here I'd like the equivalent of matlab's hold on, so I can draw multiple things) and then clear the figure (so the drawing goes away) so I can repeat the process again? The commands to plot that I'll be using are fairly simple line commands. - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] clearing a figure
belinda thom wrote: One of the reasons I'm confused is b/c when I poked around, I found a clear method: help(pylab.gcf().clear) Help on method clear in module matplotlib.figure: clear(self) method of matplotlib.figure.Figure instance Clear the figure but when I execute this on my open figure: pylab.gcf().clear() nothing happens; the figure's still displaying whatever was already on it. The reason is that in interactive mode (as with ipython -pylab) the figure is not redrawn after you execute this method. What you want instead is pylab.clf() which will call the clear and then call draw_if_interactive(). This is the big difference between most pylab functions and the corresponding axes or figure methods that they wrap: the pylab functions automatically take care of redrawing the figure if you are in an interactive mode. So far, the only thing I've found that works is to call plot differently when its time to clear the figure (pass hold=False). Subsequent calls to plot (w/o this option) keep adding to, which is great. pylab also has a hold() function similar to the Matlab command, as an alternative to passing the hold state in the plotting command call: def hold(b=None): Set the hold state. If hold is None (default), toggle the hold state. Else set the hold state to boolean value b. Eg hold() # toggle hold hold(True) # hold is on hold(False) # hold is off When hold is True, subsequent plot commands will be added to the current axes. When hold is False, the current axes and figure will be cleared on the next plot command Eric Is passing a hold=False arg to a drawing command the preferred way to clear a figure, or is clear() not working properly? Many thanks, --b On Jan 9, 2007, at 7:50 PM, belinda thom wrote: Hello, I'm a new matplotlib user, coming from the Matlab end. Is there a standard way to create a figure (here I'd like the equivalent of matlab's hold on, so I can draw multiple things) and then clear the figure (so the drawing goes away) so I can repeat the process again? The commands to plot that I'll be using are fairly simple line commands. - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users