Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74c55a6

Browse files
author
Phil Elson
committed
Fix lasso example.
1 parent bf81821 commit 74c55a6

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

examples/event_handling/lasso_demo.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
selected points
55
66
This is currently a proof-of-concept implementation (though it is
7-
usable as is). There will be some refinement of the API and the
8-
inside polygon detection routine.
7+
usable as is). There will be some refinement of the API.
98
"""
109
from matplotlib.widgets import Lasso
11-
from matplotlib.nxutils import points_inside_poly
10+
import matplotlib.mlab
11+
from matplotlib.path import Path
1212
from matplotlib.colors import colorConverter
1313
from matplotlib.collections import RegularPolyCollection
1414

@@ -18,7 +18,7 @@
1818

1919
class Datum:
2020
colorin = colorConverter.to_rgba('red')
21-
colorout = colorConverter.to_rgba('green')
21+
colorout = colorConverter.to_rgba('blue')
2222
def __init__(self, x, y, include=False):
2323
self.x = x
2424
self.y = y
@@ -46,21 +46,20 @@ def __init__(self, ax, data):
4646
ax.add_collection(self.collection)
4747

4848
self.cid = self.canvas.mpl_connect('button_press_event', self.onpress)
49-
self.ind = None
5049

5150
def callback(self, verts):
5251
facecolors = self.collection.get_facecolors()
53-
ind = nonzero(points_inside_poly(self.xys, verts))[0]
52+
p = Path(verts)
5453
for i in range(self.Nxy):
55-
if i in ind:
54+
if p.contains_point(self.xys[i]):
5655
facecolors[i] = Datum.colorin
5756
else:
5857
facecolors[i] = Datum.colorout
5958

6059
self.canvas.draw_idle()
6160
self.canvas.widgetlock.release(self.lasso)
6261
del self.lasso
63-
self.ind = ind
62+
6463
def onpress(self, event):
6564
if self.canvas.widgetlock.locked(): return
6665
if event.inaxes is None: return

0 commit comments

Comments
 (0)