Note
Go to the endto download the full example code.
Zoom modifies other Axes#
This example shows how to connect events in one window, for example, a mousepress, to another figure window.
If you click on a point in the first window, the z and y limits of the secondwill be adjusted so that the center of the zoom in the second window will bethe (x, y) coordinates of the clicked point.
Note the diameter of the circles in the scatter are defined in points**2, sotheir size is independent of the zoom.
Note
This example exercises the interactive capabilities of Matplotlib, and thiswill not appear in the static documentation. Please run this code on yourmachine to see the interactivity.
You can copy and paste individual parts, or download the entire exampleusing the link at the bottom of the page.
importmatplotlib.pyplotaspltimportnumpyasnp# Fixing random state for reproducibilitynp.random.seed(19680801)figsrc,axsrc=plt.subplots(figsize=(3.7,3.7))figzoom,axzoom=plt.subplots(figsize=(3.7,3.7))axsrc.set(xlim=(0,1),ylim=(0,1),autoscale_on=False,title='Click to zoom')axzoom.set(xlim=(0.45,0.55),ylim=(0.4,0.6),autoscale_on=False,title='Zoom window')x,y,s,c=np.random.rand(4,200)s*=200axsrc.scatter(x,y,s,c)axzoom.scatter(x,y,s,c)defon_press(event):ifevent.button!=1:returnx,y=event.xdata,event.ydataaxzoom.set_xlim(x-0.1,x+0.1)axzoom.set_ylim(y-0.1,y+0.1)figzoom.canvas.draw()figsrc.canvas.mpl_connect('button_press_event',on_press)plt.show()

