Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix lasso example. #732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix lasso example.
  • Loading branch information
Phil Elson committed Mar 1, 2012
commit 74c55a6b78fa2da638fc5d730f7d7eecc9df2596
15 changes: 7 additions & 8 deletions 15 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.