14
14
np .random .seed (19680801 )
15
15
16
16
fig , (ax1 , ax2 ) = plt .subplots (2 , figsize = (8 , 6 ))
17
- ax1 .set (facecolor = '#FFFFCC' )
18
17
19
18
x = np .arange (0.0 , 5.0 , 0.01 )
20
19
y = np .sin (2 * np .pi * x ) + 0.5 * np .random .randn (len (x ))
21
20
22
- ax1 .plot (x , y , '-' )
21
+ ax1 .plot (x , y )
23
22
ax1 .set_ylim (- 2 , 2 )
24
- ax1 .set_title ('Press left mouse button and drag to test' )
23
+ ax1 .set_title ('Press left mouse button and drag '
24
+ 'to select a region in the top graph' )
25
25
26
- ax2 .set (facecolor = '#FFFFCC' )
27
- line2 , = ax2 .plot (x , y , '-' )
26
+ line2 , = ax2 .plot ([], [])
28
27
29
28
30
29
def onselect (xmin , xmax ):
31
30
indmin , indmax = np .searchsorted (x , (xmin , xmax ))
32
31
indmax = min (len (x ) - 1 , indmax )
33
32
34
- thisx = x [indmin :indmax ]
35
- thisy = y [indmin :indmax ]
36
- line2 .set_data (thisx , thisy )
37
- ax2 .set_xlim (thisx [0 ], thisx [- 1 ])
38
- ax2 .set_ylim (thisy .min (), thisy .max ())
33
+ region_x = x [indmin :indmax ]
34
+ region_y = y [indmin :indmax ]
35
+ line2 .set_data (region_x , region_y )
36
+ ax2 .set_xlim (region_x [0 ], region_x [- 1 ])
37
+ ax2 .set_ylim (region_y .min (), region_y .max ())
39
38
fig .canvas .draw ()
40
39
41
40
#############################################################################
@@ -47,7 +46,7 @@ def onselect(xmin, xmax):
47
46
48
47
49
48
span = SpanSelector (ax1 , onselect , 'horizontal' , useblit = True ,
50
- rectprops = dict (alpha = 0.5 , facecolor = 'red ' ))
49
+ rectprops = dict (alpha = 0.5 , facecolor = 'tab:blue ' ))
51
50
# Set useblit=True on most backends for enhanced performance.
52
51
53
52
0 commit comments