99a lasso loop around the points on the graph. To draw, just click
1010on the graph, hold, and drag it around the points you need to select.
1111"""
12- from __future__ import print_function
1312
14- from six . moves import input
13+ from __future__ import print_function
1514
1615import numpy as np
1716
@@ -79,7 +78,6 @@ def disconnect(self):
7978if __name__ == '__main__' :
8079 import matplotlib .pyplot as plt
8180
82- plt .ion ()
8381 # Fixing random state for reproducibility
8482 np .random .seed (19680801 )
8583
@@ -91,11 +89,15 @@ def disconnect(self):
9189 pts = ax .scatter (data [:, 0 ], data [:, 1 ], s = 80 )
9290 selector = SelectFromCollection (ax , pts )
9391
94- plt .draw ()
95- input ('Press Enter to accept selected points' )
96- print ("Selected points:" )
97- print (selector .xys [selector .ind ])
98- selector .disconnect ()
92+ def accept (event ):
93+ if event .key == "enter" :
94+ print ("Selected points:" )
95+ print (selector .xys [selector .ind ])
96+ selector .disconnect ()
97+ ax .set_title ("" )
98+ fig .canvas .draw ()
99+
100+ fig .canvas .mpl_connect ("key_press_event" , accept )
101+ ax .set_title ("Press enter to accept selected points." )
99102
100- # Block end of script so you can check that the lasso is disconnected.
101- input ('Press Enter to quit' )
103+ plt .show ()
0 commit comments