6
6
This example shows how to connect events in one window, for example, a mouse
7
7
press, to another figure window.
8
8
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.
12
12
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.
15
15
"""
16
- from matplotlib .pyplot import figure , show
16
+
17
+ from matplotlib import pyplot as plt
17
18
import 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
+
26
27
x , y , s , c = np .random .rand (4 , 200 )
27
28
s *= 200
28
29
29
-
30
30
axsrc .scatter (x , y , s , c )
31
31
axzoom .scatter (x , y , s , c )
32
32
@@ -40,4 +40,4 @@ def onpress(event):
40
40
figzoom .canvas .draw ()
41
41
42
42
figsrc .canvas .mpl_connect ('button_press_event' , onpress )
43
- show ()
43
+ plt . show ()
0 commit comments