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.php&p=sourceforge&CID=DEVDEV _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users