remove artist from axes?

> Hi,
>
> I don't see an obvious way to remove a line from an axes object.
>
> Shall I add remove_child(h) which searches through all the lists
> of containers and removes the one that I don't want?

That's one way to do it, but you might consider something along the
lines -- every time someone adds an Artist anywhere in the figure,
they add an entry into a Figure remove dictionary that maps the artist
to a function to remove it

class Figure:
  def register_remove(self, artist, func):
      'register a function to remove an artist'
      self.removemap[artist] = func
      self.lastArtist = artist # this can be used to handle Gael's request

  def remove_artist(self, artist):
    'remove the artist'
    func = self.removemap.get(artist, None)
    if func is None: return
    func() # poof, it's gone
    del self.removemap(artist)

  def remove_last(self):
    'remove the most recently registered artist'
    self.remove_artist(self.lastArtist)
    self.lastArtist = None
class Axes:
  def add_line(self, line):
      self.figure.register_remove(line, lambda x: self.lines.remove(line))
      self.lines.append(line)

I'm not to keen on yet another registry, especially since it will have to
be maintained when, e.g., cla() is called.

How about storing the remove function with the artist itself? Then it
would just be h.remove() rather than fig.remove_artist(h).

BTW, I can't think of a use case for 'remove last' from an applications
standpoint. Maybe it would be useful to someone entering plot commands
from the console, but even then it is a poor substitute for 'undo'.

Then the user won't need to know whether the artist is stored by the
Axes, Axis, XTick, etc... This is likely more efficient and easier to
implement than recursively searching....

On the topic of efficiency, every tick line (1,2) grid line (1,2) and
every tick label (1,2) has an artist associated with it. Is there any
reason not to represent this as one or two line collections and a text
collection? Our application has multiple panels in a wxAUI interface,
and graph rendering is slow even on tiny data sets.

  - Paul

···

On Mon, Jul 16, 2007 at 08:38:17AM -0500, John Hunter wrote:

On 7/15/07, Paul Kienzle <pkienzle@...537...> wrote: