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

Skip to content

Commit 99f3a36

Browse files
committed
added a line vertex selector widget
svn path=/branches/v0_91_maint/; revision=5271
1 parent 579f9cd commit 99f3a36

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

CODING_GUIDE

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ and standards. Please edit and extend this document.
99
svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk matplotlib --username=youruser --password=yourpass
1010

1111

12-
# checking out the main src
13-
svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/matplotlib matplotlib --username=youruser --password=yourpass
14-
15-
# branch checkouts, eg the transforms branch
16-
svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/transforms transbranch
17-
1812
== Committing changes ==
1913

2014
When committing changes to matplotlib, there are a few things to bear

lib/matplotlib/lines.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ def get_markerfacecolor(self):
569569

570570
def get_markersize(self): return self._markersize
571571

572+
def get_data(self, orig=True):
573+
'return the xdata, ydata; if orig is True, return the original data'
574+
return self.get_xdata(orig=orig), self.get_ydata(orig=orig)
575+
572576
def get_xdata(self, orig=True):
573577
"""
574578
return the xdata; if orig is true return the original data,
@@ -1460,6 +1464,57 @@ def is_dashed(self):
14601464
'return True if line is dashstyle'
14611465
return self._linestyle in ('--', '-.', ':')
14621466

1467+
class VertexSelector:
1468+
"""
1469+
manage the callbacks to maintain a list of selected vertices for
1470+
matplotlib.lines.Lin2D. Derived classes should override
1471+
process_selected to do something with the picks
1472+
"""
1473+
def __init__(self, line):
1474+
"""
1475+
Initialize the class with a matplotlib.lines.Line2D instance.
1476+
The line should already be added to some matplotlib.axes.Axes
1477+
instance and should have the picker property set.
1478+
"""
1479+
if not hasattr(line, 'axes'):
1480+
raise RuntimeError('You must first add the line to the Axes')
1481+
1482+
if line.get_picker() is None:
1483+
raise RuntimeError('You must first set the picker property of the line')
1484+
1485+
self.axes = line.axes
1486+
self.line = line
1487+
self.canvas = self.axes.figure.canvas
1488+
self.cid = self.canvas.mpl_connect('pick_event', self.onpick)
1489+
1490+
self.ind = set()
1491+
1492+
1493+
def process_selected(self, ind, xs, ys):
1494+
"""
1495+
Default do nothing implementation of the process_selected method.
1496+
1497+
ind are the indices of the selected vertices. xs and ys are
1498+
the coordinates of the selected vertices.
1499+
"""
1500+
pass
1501+
1502+
def onpick(self, event):
1503+
'when the line is picked, update the set of selected indicies'
1504+
if event.artist is not self.line: return
1505+
1506+
for i in event.ind:
1507+
if i in self.ind:
1508+
self.ind.remove(i)
1509+
else:
1510+
self.ind.add(i)
1511+
1512+
1513+
ind = list(self.ind)
1514+
ind.sort()
1515+
ind = npy.array(ind)
1516+
xdata, ydata = self.line.get_data()
1517+
self.process_selected(ind, xdata[ind], ydata[ind])
14631518

14641519
lineStyles = Line2D._lineStyles
14651520
lineMarkers = Line2D._markers

0 commit comments

Comments
 (0)