Removing a line from a plot

Thank you guys, and thanks for the Wiki entry :wink: Andrea.

Since ax.lines is just a list, you can also use the "remove" method

  line1, = ax.plot(something)
  line2, = ax.plot(somethingelse)
  line3, line4 = ax.plot(x3, y3, x4, y4)

  ax.lines.remove(line3)

JDH

With the caveat that I think this is O(N) in the length of the list,
with comparison operations at each step. I think 'del alist[i]' is
also O(N), but amortized and with *much* smaller constant (only cheap
internal pointer shuffling, without any real Python work).

Someone with better knowledge of the list object internals, feel free
to correct the above (I'm actually curious if the reality is
different).

Cheers,

f

···

On 11/9/06, John Hunter <jdhunter@...4...> wrote:

    > Thank you guys, and thanks for the Wiki entry :wink: Andrea.

Since ax.lines is just a list, you can also use the "remove" method

  line1, = ax.plot(something)
  line2, = ax.plot(somethingelse)
  line3, line4 = ax.plot(x3, y3, x4, y4)

  ax.lines.remove(line3)

I'm new to matplotlib; I was using PyX but matplotlib seems further developed for what I want to do.

One of the problems that I'm having is simply getting started. I've discovered that there are a whole bunch of dependencies that weren't obvious in the manual:

  * You need PyNum (documented)
  * You need wxPython (not documented that I've found)

Nevertheless, I'm still having problems. The example in the beginning of the manual doesn't work for me; array() is undefined:

% python
Python 2.4.3 (#1, Mar 30 2006, 11:02:16)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pylab import *
>>> dt = 0.01
>>> t = arrange(0,10,dt)
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
NameError: name 'arrange' is not defined
>>>

I'm using a MacOS machine running 10.4.

Any suggestions?

Hi,

       * You need PyNum (documented)

I suppose you meant NumPy

       * You need wxPython (not documented that I've found)

No, I don't remember that particular need, unless things have changed
in the meanwhile. If so, please correct my ignorance.

Python 2.4.3 (#1, Mar 30 2006, 11:02:16)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pylab import *
>>> dt = 0.01
>>> t = arrange(0,10,dt)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'arrange' is not defined

I suppose you meant "arange" and not "arrange".

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

Hi Gang,

Thank you guys, and thanks for the Wiki entry :wink: Andrea.

I have a further small question. When I add a line to my plot, the
axes gracefully rescale to accomodate the new data plotted. However,
when I remove a line, they do not rescale, even if I call:

locator = self.leftaxis.yaxis.get_major_locator()
locator.autoscale()

Or:

self.leftaxis.autoscale_view(scalex=False, scaley=True)

I also call self.canvas.draw(), self.Refresh()... nothing happens. Is
there a way to make the axes rescale after removing a line from a
plot?

Thank you.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/