@@ -569,6 +569,10 @@ def get_markerfacecolor(self):
569
569
570
570
def get_markersize (self ): return self ._markersize
571
571
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
+
572
576
def get_xdata (self , orig = True ):
573
577
"""
574
578
return the xdata; if orig is true return the original data,
@@ -1460,6 +1464,57 @@ def is_dashed(self):
1460
1464
'return True if line is dashstyle'
1461
1465
return self ._linestyle in ('--' , '-.' , ':' )
1462
1466
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 ])
1463
1518
1464
1519
lineStyles = Line2D ._lineStyles
1465
1520
lineMarkers = Line2D ._markers
0 commit comments