Hi NG, I posted this question few months ago and I didn't receive any answer, so I'll try to rephrase my problem. I have a GUI written in wxPython, the main portion of it is a matplotlib canvas. There is a tree control on the left with checkboxes: if the user checks a checkbox, I add a line on the plot. So far so good. The problem comes when the user *un-checks* the checkbox. I would like to remove the line from the plot, but the only way I found to do it is to do: line.set_linestyle("None") Which is not very nice (and not very correct), as it seems to me that the line is still there (invisible, but still there). Am I right or have I completely misunderstood the set_linestyle behavior? If this method is not correct, is there any alternative that I could try to erase completely the line from the plot (and from the legend, obviously)? The alternative of replotting everything just because a line should be erased came into my mind but I discarded it because it is fantastically time consuming with my graphs. Thank you for every hint. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.virgilio.it/infinity77/
> I have a GUI written in wxPython, the main portion of it is a > matplotlib canvas. There is a tree control on the left with > checkboxes: if the user checks a checkbox, I add a line on the plot. > So far so good. The problem comes when the user *un-checks* the > checkbox. I would like to remove the line from the plot, but the only > way I found to do it is to do: To suppress the last line drawn: del(gca().lines[-1]) (replace gca() by the handle of the subplot you're acting on)
Thank you guys, and thanks for the Wiki entry ;-) Andrea. On 11/9/06, Pierre GM <pgm...@gm...> wrote: > > > I have a GUI written in wxPython, the main portion of it is a > > matplotlib canvas. There is a tree control on the left with > > checkboxes: if the user checks a checkbox, I add a line on the plot. > > So far so good. The problem comes when the user *un-checks* the > > checkbox. I would like to remove the line from the plot, but the only > > way I found to do it is to do: > > To suppress the last line drawn: > del(gca().lines[-1]) > > (replace gca() by the handle of the subplot you're acting on) > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.virgilio.it/infinity77/
>>>>> "Andrea" == Andrea Gavana <and...@gm...> writes: Andrea> Thank you guys, and thanks for the Wiki entry ;-) 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
On 11/9/06, John Hunter <jdh...@ac...> wrote: > >>>>> "Andrea" == Andrea Gavana <and...@gm...> writes: > > Andrea> Thank you guys, and thanks for the Wiki entry ;-) 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) 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
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, Andrea> Thank you guys, and thanks for the Wiki entry ;-) 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/
>>>>> "Andrea" == Andrea Gavana <and...@gm...> writes: Andrea> Hi Gang, Thank you guys, and thanks for the Wiki entry ;-) Andrea> Andrea. Andrea> I have a further small question. When I add a line to my Andrea> plot, the axes gracefully rescale to accomodate the new Andrea> data plotted. However, when I remove a line, they do not Andrea> rescale, even if I call: Andrea> locator = self.leftaxis.yaxis.get_major_locator() Andrea> locator.autoscale() Andrea> Or: Andrea> self.leftaxis.autoscale_view(scalex=False, scaley=True) Andrea> I also call self.canvas.draw(), self.Refresh()... nothing Andrea> happens. Is there a way to make the axes rescale after Andrea> removing a line from a plot? The Axes instance has two BBox (bounding box) instances -- the dataLim and the viewLim. The dataLim store a rectangle that bounds all the data in the Axes, and the viewLim are the x and y view limits, ie, xlim and ylim. Autoscaling sets the viewLim based on the dataLim. When you add lines to the plot, the dataLim are updated, but when you remove data with del ax.lines[-1] etc, the dataLim are not updated. If all you have in the Axes are line instances, you can update the dataLim with the remaining lines, but first you must tell it to ignore it's current limits. You do this with the ignore flag # after removing a line, do ignore = True for line in ax.lines: x = line.get_xdata() y = line.get_ydata() ax.dataLim.update_numerix(x, y, ignore) ignore = False If you have other data in your Axes, eg Polygons or Collections, it is a bit more complicated. It would be useful to have an Axes method like "auto_datalim" to for the datalim to readjust to all the current data. After you have tested this, would you mind updating the wiki with this information? Thanks, JDH
Hi John, sorry to come back so late with this subject. Well, I have tried your suggestion: > When you add lines to the plot, the dataLim are updated, but when you > remove data with del ax.lines[-1] etc, the dataLim are not updated. > If all you have in the Axes are line instances, you can update the > dataLim with the remaining lines, but first you must tell it to ignore > it's current limits. You do this with the ignore flag > > # after removing a line, do > ignore = True > for line in ax.lines: > x = line.get_xdata() > y = line.get_ydata() > ax.dataLim.update_numerix(x, y, ignore) > ignore = False > No way, it doesn't update the axes. Uhm, in my plot I have only lines and one legend, nothing more. Even if I try a simple case with 2 lines and I remove one of them, the axes still stay with their previous limits. I must be missing something. > After you have tested this, would you mind updating the wiki with this > information? No problem, as soon as I am able to update the axes, I will add that info to the wiki. Thank you. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.virgilio.it/infinity77/
Anyone find an answer to this one? I'm running into this issue with 0.90.1and I found this in the archives. I tried the suggested code and it doesn't seem to work for me. Right now my workaround is min_x = min([min(line.get_xdata()) for line in self.axes.lines]) max_x = max([max(line.get_xdata()) for line in self.axes.lines]) self.axes.set_xlim(min_x,max_x) Any suggestions? Thanks, Greg On Tue, Nov 14, 2006 at 8:13 PM, Andrea Gavana <and...@gm...> wrote: > Hi John, > > sorry to come back so late with this subject. Well, I have tried > your suggestion: > > > When you add lines to the plot, the dataLim are updated, but when you > > remove data with del ax.lines[-1] etc, the dataLim are not updated. > > If all you have in the Axes are line instances, you can update the > > dataLim with the remaining lines, but first you must tell it to ignore > > it's current limits. You do this with the ignore flag > > > > # after removing a line, do > > ignore = True > > for line in ax.lines: > > x = line.get_xdata() > > y = line.get_ydata() > > ax.dataLim.update_numerix(x, y, ignore) > > ignore = False > > > > No way, it doesn't update the axes. Uhm, in my plot I have only lines > and one legend, nothing more. Even if I try a simple case with 2 lines > and I remove one of them, the axes still stay with their previous > limits. I must be missing something. > > > After you have tested this, would you mind updating the wiki with this > > information? > > No problem, as soon as I am able to update the axes, I will add that > info to the wiki. > > Thank you. > > Andrea. > > "Imagination Is The Only Weapon In The War Against Reality." > http://xoomer.virgilio.it/infinity77/ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users >