1616fig , (ax1 , ax2 ) = plt .subplots (2 , figsize = (8 , 6 ))
1717
1818x = np .arange (0.0 , 5.0 , 0.01 )
19- y = np .sin (2 * np .pi * x ) + 0.5 * np .random .randn (len (x ))
19+ y = np .sin (2 * np .pi * x ) + 0.5 * np .random .randn (len (x ))
2020
2121ax1 .plot (x , y )
2222ax1 .set_ylim (- 2 , 2 )
2323ax1 .set_title ('Press left mouse button and drag '
2424 'to select a region in the top graph' )
2525
26- line2 , = ax2 .plot ([], [])
26+ ( line2 ,) = ax2 .plot ([], [])
2727
2828
2929def onselect (xmin , xmax ):
@@ -37,7 +37,8 @@ def onselect(xmin, xmax):
3737 line2 .set_data (region_x , region_y )
3838 ax2 .set_xlim (region_x [0 ], region_x [- 1 ])
3939 ax2 .set_ylim (region_y .min (), region_y .max ())
40- fig .canvas .draw ()
40+ fig .canvas .draw_idle ()
41+
4142
4243#############################################################################
4344# .. note::
@@ -47,8 +48,15 @@ def onselect(xmin, xmax):
4748#
4849
4950
50- span = SpanSelector (ax1 , onselect , 'horizontal' , useblit = True ,
51- rectprops = dict (alpha = 0.5 , facecolor = 'tab:blue' ))
51+ span = SpanSelector (
52+ ax1 ,
53+ onselect ,
54+ "horizontal" ,
55+ useblit = True ,
56+ rectprops = dict (alpha = 0.5 , facecolor = "tab:blue" ),
57+ interactive = True ,
58+ drag_from_anywhere = True
59+ )
5260# Set useblit=True on most backends for enhanced performance.
5361
5462
0 commit comments