How to remove an element from a graph?

Assume I am running an interactive session, using
        ipython -pylab

and have added a bunch of curves
        x = linspace(0, 10, 100 )
        plot( x, sin(x) )
        plot( x, cos(x) )

and also added a text label
        text( 1, 1, "Hello" )

But now I decide that I don't want the text anymore.
What's the best way to remove it from the graph?

(Because the graph is complicated I don't just want
to clf() and start all over - I just want to remove that
one element.)

What I have found is that if I save the object created,
I can invoke its remove() function:
        t =text( 2, 1, "Hello again" )
        t.remove()
        draw()

Is this the best way to do this, or is there another way
(or one that does not require an explicit draw()?). Also,
what if I have failed to save the text instance - do I have
to walk the object tree using findobj()?

Thanks!

Best,

                Ph.

Is this the best way to do this, or is there another way
(or one that does not require an explicit draw()?). Also,

Any change in your figure is realized when you "draw()" the figure. So
there is no way that does not require an explicit draw.

An alternative is to make the artist invisible (use set_visible method).

what if I have failed to save the text instance - do I have
to walk the object tree using findobj()?

All the artists that are drawn are kept in the figure instance, so you
can inspect the figure instance.
And you may use findobj for that if you want.
On the other hand, Axes.texts keeps a list of text instances in the
axes (e.g., gca().texts).

Regards,

-JJ

···

On Sun, May 16, 2010 at 3:19 PM, Philipp K. Janert <python@...3103...> wrote:

For more detail see the artist tutorial which describes the various
containers and how to remove objects from them

http://matplotlib.sourceforge.net/users/artists.html#axes-container

JDH

···

On Tue, May 18, 2010 at 12:58 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote:

All the artists that are drawn are kept in the figure instance, so you
can inspect the figure instance.
And you may use findobj for that if you want.
On the other hand, Axes.texts keeps a list of text instances in the
axes (e.g., gca().texts).

Thanks.

···

On Tuesday 18 May 2010 12:13:27 pm John Hunter wrote:

On Tue, May 18, 2010 at 12:58 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote:
> All the artists that are drawn are kept in the figure instance, so you
> can inspect the figure instance.
> And you may use findobj for that if you want.
> On the other hand, Axes.texts keeps a list of text instances in the
> axes (e.g., gca().texts).

For more detail see the artist tutorial which describes the various
containers and how to remove objects from them

http://matplotlib.sourceforge.net/users/artists.html#axes-container

JDH