9
9
a lasso loop around the points on the graph. To draw, just click
10
10
on the graph, hold, and drag it around the points you need to select.
11
11
"""
12
- from __future__ import print_function
13
12
14
- from six . moves import input
13
+ from __future__ import print_function
15
14
16
15
import numpy as np
17
16
@@ -79,7 +78,6 @@ def disconnect(self):
79
78
if __name__ == '__main__' :
80
79
import matplotlib .pyplot as plt
81
80
82
- plt .ion ()
83
81
# Fixing random state for reproducibility
84
82
np .random .seed (19680801 )
85
83
@@ -91,11 +89,15 @@ def disconnect(self):
91
89
pts = ax .scatter (data [:, 0 ], data [:, 1 ], s = 80 )
92
90
selector = SelectFromCollection (ax , pts )
93
91
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." )
99
102
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