@@ -30,23 +30,23 @@ def line_select_callback(eclick, erelease):
3030
3131def toggle_selector (event ):
3232 print (' Key pressed.' )
33- if event .key in ['Q' , 'q' ] and toggle_selector .RS .active :
34- print (' RectangleSelector deactivated.' )
35- toggle_selector .RS .set_active (False )
36- if event .key in ['A' , 'a' ] and not toggle_selector .RS .active :
37- print (' RectangleSelector activated.' )
38- toggle_selector .RS .set_active (True )
33+ if event .key == 't' :
34+ if toggle_selector .RS .active :
35+ print (' RectangleSelector deactivated.' )
36+ toggle_selector .RS .set_active (False )
37+ else :
38+ print (' RectangleSelector activated.' )
39+ toggle_selector .RS .set_active (True )
3940
4041
4142fig , ax = plt .subplots ()
4243N = 100000 # If N is large one can see improvement by using blitting.
43- x = np .linspace (0.0 , 10.0 , N )
44+ x = np .linspace (0 , 10 , N )
4445
45- ax .plot (x , + np .sin (.2 * np .pi * x ), lw = 3.5 , c = 'b' , alpha = .7 ) # plot something
46- ax .plot (x , + np .cos (.2 * np .pi * x ), lw = 3.5 , c = 'r' , alpha = .5 )
47- ax .plot (x , - np .sin (.2 * np .pi * x ), lw = 3.5 , c = 'g' , alpha = .3 )
48-
49- print ("\n click --> release" )
46+ ax .plot (x , np .sin (2 * np .pi * x )) # plot something
47+ ax .set_title (
48+ "Click and drag to draw a rectangle.\n "
49+ "Press 't' to toggle the selector on and off." )
5050
5151# drawtype is 'box' or 'line' or 'none'
5252toggle_selector .RS = RectangleSelector (ax , line_select_callback ,
0 commit comments