66This example shows how to connect events in one window, for example, a mouse
77press, to another figure window.
88
9- If you click on a point in the first window, the z and y limits of the
10- second will be adjusted so that the center of the zoom in the second
11- window will be the x,y coordinates of the clicked point.
9+ If you click on a point in the first window, the z and y limits of the second
10+ will be adjusted so that the center of the zoom in the second window will be
11+ the x,y coordinates of the clicked point.
1212
13- Note the diameter of the circles in the scatter are defined in
14- points**2, so their size is independent of the zoom
13+ Note the diameter of the circles in the scatter are defined in points**2, so
14+ their size is independent of the zoom.
1515"""
16- from matplotlib .pyplot import figure , show
16+
17+ import matplotlib .pyplot as plt
1718import numpy as np
18- figsrc = figure ()
19- figzoom = figure ()
20-
21- axsrc = figsrc . add_subplot ( 111 , xlim = (0 , 1 ), ylim = (0 , 1 ), autoscale_on = False )
22- axzoom = figzoom . add_subplot ( 111 , xlim = ( 0.45 , 0.55 ), ylim = ( 0.4 , .6 ),
23- autoscale_on = False )
24- axsrc . set_title ( 'Click to zoom ' )
25- axzoom . set_title ( 'zoom window' )
19+
20+ figsrc , axsrc = plt . subplots ()
21+ figzoom , axzoom = plt . subplots ()
22+ axsrc . set ( xlim = (0 , 1 ), ylim = (0 , 1 ), autoscale_on = False ,
23+ title = 'Click to zoom' )
24+ axzoom . set ( xlim = ( 0.45 , 0.55 ), ylim = ( 0.4 , 0.6 ), autoscale_on = False ,
25+ title = 'Zoom window ' )
26+
2627x , y , s , c = np .random .rand (4 , 200 )
2728s *= 200
2829
29-
3030axsrc .scatter (x , y , s , c )
3131axzoom .scatter (x , y , s , c )
3232
@@ -40,4 +40,4 @@ def onpress(event):
4040 figzoom .canvas .draw ()
4141
4242figsrc .canvas .mpl_connect ('button_press_event' , onpress )
43- show ()
43+ plt . show ()
0 commit comments