From: Andrew S. <str...@as...> - 2008-02-19 06:20:03
Attachments:
pick_event_demo3.py
fixup_masked_for_picking.patch
|
I just ran into a bug with picking of lines. I changed the line style in figure 1, subplot 1 to 'o-' (from 'o') and ripped out most of everything else in examples/pick_event_demo.py to create pick_event_demo3.py (attached). When I run this and I attempt to click on points, I get Traceback (most recent call last): File "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py", line 193, in button_press_event FigureCanvasBase.button_press_event(self, x, y, event.button) File "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/backend_bases.py", line 915, in button_press_event self.callbacks.process(s, mouseevent) File "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/cbook.py", line 157, in process func(*args, **kwargs) File "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/backend_bases.py", line 849, in pick self.figure.pick(mouseevent) File "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/artist.py", line 220, in pick for a in self.get_children(): a.pick(mouseevent) File "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/axes.py", line 2155, in pick martist.Artist.pick(self,args[0]) File "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/artist.py", line 220, in pick for a in self.get_children(): a.pick(mouseevent) File "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/artist.py", line 214, in pick inside,prop = self.contains(mouseevent) File "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/lines.py", line 327, in contains ind = segment_hits(mouseevent.x,mouseevent.y,xt,yt,pixels) File "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/lines.py", line 100, in segment_hits candidates = candidates & ~point_hits[:-1] & ~point_hits[1:] TypeError: bad operand type for unary ~: 'MaskedArray' Anyhow, I spent a little while tracking this down and came up with the attached patch. I guess there's a more direct solution to the issue that this band-aid, but I hope this will jump-start someone to fix this. In the meantime, this appears to work sufficiently for my purposes... FWIW, my numpy is SVN from 16 december 2007 (after 1.0.4 and thus on the way to 1.0.5) and I'm using the old ma module. BUILDING MATPLOTLIB matplotlib: 0.98pre python: 2.5.1 (r251:54863, Oct 5 2007, 13:50:07) [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] platform: linux2 REQUIRED DEPENDENCIES numpy: 1.0.5.dev freetype2: 9.16.3 |
From: Michael D. <md...@st...> - 2008-02-19 15:55:31
|
Thanks for finding this. I just committed a slightly less band-aid-like fix in SVN r4979. There were really two bugs here: 1) A masked array is created for a line plot whenever only y values are provided, even if there are no masked values in the data. That would only be a performance bug if it weren't for... 2) The picking code for a line assumes non-masked arrays. Since the Line class already keeps around a "compressed" version of the data for drawing, it is easy enough to use that instead of the raw data. By fixing 1), 2) is no longer even an issue in your example. However, for a plot that really does have gaps, 2) needs to be fixed as well. Cheers, Mike Andrew Straw wrote: > I just ran into a bug with picking of lines. I changed the line style in > figure 1, subplot 1 to 'o-' (from 'o') and ripped out most of everything > else in examples/pick_event_demo.py to create pick_event_demo3.py > (attached). When I run this and I attempt to click on points, I get > > Traceback (most recent call last): > File > "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py", > line 193, in button_press_event > FigureCanvasBase.button_press_event(self, x, y, event.button) > File > "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/backend_bases.py", > line 915, in button_press_event > self.callbacks.process(s, mouseevent) > File > "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/cbook.py", > line 157, in process > func(*args, **kwargs) > File > "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/backend_bases.py", > line 849, in pick > self.figure.pick(mouseevent) > File > "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/artist.py", > line 220, in pick > for a in self.get_children(): a.pick(mouseevent) > File > "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/axes.py", > line 2155, in pick > martist.Artist.pick(self,args[0]) > File > "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/artist.py", > line 220, in pick > for a in self.get_children(): a.pick(mouseevent) > File > "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/artist.py", > line 214, in pick > inside,prop = self.contains(mouseevent) > File > "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/lines.py", > line 327, in contains > ind = segment_hits(mouseevent.x,mouseevent.y,xt,yt,pixels) > File > "/home/astraw/py2.5-linux-x86_64/lib/python2.5/site-packages/matplotlib/lines.py", > line 100, in segment_hits > candidates = candidates & ~point_hits[:-1] & ~point_hits[1:] > TypeError: bad operand type for unary ~: 'MaskedArray' > > Anyhow, I spent a little while tracking this down and came up with the > attached patch. I guess there's a more direct solution to the issue that > this band-aid, but I hope this will jump-start someone to fix this. In > the meantime, this appears to work sufficiently for my purposes... > > FWIW, my numpy is SVN from 16 december 2007 (after 1.0.4 and thus on the > way to 1.0.5) and I'm using the old ma module. > > BUILDING MATPLOTLIB > matplotlib: 0.98pre > python: 2.5.1 (r251:54863, Oct 5 2007, 13:50:07) [GCC > 4.1.3 20070929 (prerelease) (Ubuntu > 4.1.2-16ubuntu2)] > platform: linux2 > > REQUIRED DEPENDENCIES > numpy: 1.0.5.dev > freetype2: 9.16.3 > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > > ------------------------------------------------------------------------ > > _______________________________________________ > Matplotlib-devel mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA |
From: Paul K. <pki...@ni...> - 2008-02-19 23:45:22
|
On Tue, Feb 19, 2008 at 10:55:14AM -0500, Michael Droettboom wrote: > 2) The picking code for a line assumes non-masked arrays. Since the > Line class already keeps around a "compressed" version of the data for > drawing, it is easy enough to use that instead of the raw data. I didn't provide any masked array checks in any of the contains methods that I wrote. Do any of these need to be fixed? I won't have a lot of time over the next few months, and I will be slow to fix them. - Paul |
From: John H. <jd...@gm...> - 2008-02-20 03:56:07
|
On Feb 19, 2008 5:45 PM, Paul Kienzle <pki...@ni...> wrote: > I didn't provide any masked array checks in any of the contains methods > that I wrote. Do any of these need to be fixed? They do need to be fixed, but this is not a high priority item. Let's wait until the new maskedarray code that is now in a numpy branch goes live and official before we invest too much energy in getting masked arrays working properly here. JDH |
From: Eric F. <ef...@ha...> - 2008-02-20 04:36:55
|
John Hunter wrote: > On Feb 19, 2008 5:45 PM, Paul Kienzle <pki...@ni...> wrote: > >> I didn't provide any masked array checks in any of the contains methods >> that I wrote. Do any of these need to be fixed? > > They do need to be fixed, but this is not a high priority item. Let's > wait until the new maskedarray code that is now in a numpy branch goes > live and official before we invest too much energy in getting masked > arrays working properly here. The maskedarray branch has been merged into the svn trunk and will therefore be in the 1.05 release, coming within days. Eric |