|
4 | 4 | selected points |
5 | 5 |
|
6 | 6 | 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. |
9 | 8 | """ |
10 | 9 | from matplotlib.widgets import Lasso |
11 | | -from matplotlib.nxutils import points_inside_poly |
| 10 | +import matplotlib.mlab |
| 11 | +from matplotlib.path import Path |
12 | 12 | from matplotlib.colors import colorConverter |
13 | 13 | from matplotlib.collections import RegularPolyCollection |
14 | 14 |
|
|
18 | 18 |
|
19 | 19 | class Datum: |
20 | 20 | colorin = colorConverter.to_rgba('red') |
21 | | - colorout = colorConverter.to_rgba('green') |
| 21 | + colorout = colorConverter.to_rgba('blue') |
22 | 22 | def __init__(self, x, y, include=False): |
23 | 23 | self.x = x |
24 | 24 | self.y = y |
@@ -46,21 +46,20 @@ def __init__(self, ax, data): |
46 | 46 | ax.add_collection(self.collection) |
47 | 47 |
|
48 | 48 | self.cid = self.canvas.mpl_connect('button_press_event', self.onpress) |
49 | | - self.ind = None |
50 | 49 |
|
51 | 50 | def callback(self, verts): |
52 | 51 | facecolors = self.collection.get_facecolors() |
53 | | - ind = nonzero(points_inside_poly(self.xys, verts))[0] |
| 52 | + p = Path(verts) |
54 | 53 | for i in range(self.Nxy): |
55 | | - if i in ind: |
| 54 | + if p.contains_point(self.xys[i]): |
56 | 55 | facecolors[i] = Datum.colorin |
57 | 56 | else: |
58 | 57 | facecolors[i] = Datum.colorout |
59 | 58 |
|
60 | 59 | self.canvas.draw_idle() |
61 | 60 | self.canvas.widgetlock.release(self.lasso) |
62 | 61 | del self.lasso |
63 | | - self.ind = ind |
| 62 | + |
64 | 63 | def onpress(self, event): |
65 | 64 | if self.canvas.widgetlock.locked(): return |
66 | 65 | if event.inaxes is None: return |
|
0 commit comments