From: Carl M. <car...@bi...> - 2005-05-06 09:33:55
|
So obvious when someone tells you! Thanks for this, it is exactly what I was looking for. Carl ----- Original Message ----- From: "John Hunter" <jdh...@ac...> To: "Carl Mouser" <car...@bi...> Cc: <mat...@li...> Sent: Thursday, May 05, 2005 11:55 PM Subject: Re: [Matplotlib-users] Deleting lines from a plot > > If you know which line you want to delete, you can call > ax.lines.remove(line) where line is a line instance. > > In [1]: line1, = plot(rand(10), 'ro') > In [2]: line2, = plot(rand(20), 'b--s') > In [3]: ax = gca() > In [4]: ax.lines.remove(line1) > In [5]: draw() > > If you haven't saved the line instance, but can otherwise identify it > (eg you know it was the first line you plotted), you can do something > like > > ax.lines.remove(ax.lines[0]) > > or if you have labeled the line, you can identify and remove it with > > plot(x,y,label='my line') > line = [line for line in ax.lines if line.get_label()=='my line'][0] > ax.lines.remove(line) > > JDH |