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:
> 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
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
> 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
pylab also has a hold() function similar to the Matlab command, as an
alternative to passing the hold state in the plotting command call:
Set the hold state. If hold is None (default), toggle the
hold state. Else set the hold state to boolean value b.
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
> 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,
> On Jan 9, 2007, at 7:50 PM, belinda thom wrote:
>> 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.