Skip to content

Commit

Permalink
Fix lasso example.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Elson committed Mar 1, 2012
1 parent bf81821 commit 74c55a6
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions examples/event_handling/lasso_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
selected points
This is currently a proof-of-concept implementation (though it is
usable as is). There will be some refinement of the API and the
inside polygon detection routine.
usable as is). There will be some refinement of the API.
"""
from matplotlib.widgets import Lasso
from matplotlib.nxutils import points_inside_poly
import matplotlib.mlab
from matplotlib.path import Path
from matplotlib.colors import colorConverter
from matplotlib.collections import RegularPolyCollection

Expand All @@ -18,7 +18,7 @@

class Datum:
colorin = colorConverter.to_rgba('red')
colorout = colorConverter.to_rgba('green')
colorout = colorConverter.to_rgba('blue')
def __init__(self, x, y, include=False):
self.x = x
self.y = y
Expand Down Expand Up @@ -46,21 +46,20 @@ def __init__(self, ax, data):
ax.add_collection(self.collection)

self.cid = self.canvas.mpl_connect('button_press_event', self.onpress)
self.ind = None

def callback(self, verts):
facecolors = self.collection.get_facecolors()
ind = nonzero(points_inside_poly(self.xys, verts))[0]
p = Path(verts)
for i in range(self.Nxy):
if i in ind:
if p.contains_point(self.xys[i]):
facecolors[i] = Datum.colorin
else:
facecolors[i] = Datum.colorout

self.canvas.draw_idle()
self.canvas.widgetlock.release(self.lasso)
del self.lasso
self.ind = ind

def onpress(self, event):
if self.canvas.widgetlock.locked(): return
if event.inaxes is None: return
Expand Down

0 comments on commit 74c55a6

Please sign in to comment.