.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/event_handling/zoom_window.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_event_handling_zoom_window.py: =========== Zoom Window =========== This example shows how to connect events in one window, for example, a mouse press, to another figure window. If you click on a point in the first window, the z and y limits of the second will be adjusted so that the center of the zoom in the second window will be the (x, y) coordinates of the clicked point. Note the diameter of the circles in the scatter are defined in points**2, so their size is independent of the zoom. .. note:: This example exercises the interactive capabilities of Matplotlib, and this will not appear in the static documentation. Please run this code on your machine to see the interactivity. You can copy and paste individual parts, or download the entire example using the link at the bottom of the page. .. GENERATED FROM PYTHON SOURCE LINES 24-55 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /gallery/event_handling/images/sphx_glr_zoom_window_001.png :alt: Click to zoom :srcset: /gallery/event_handling/images/sphx_glr_zoom_window_001.png, /gallery/event_handling/images/sphx_glr_zoom_window_001_2_00x.png 2.00x :class: sphx-glr-multi-img * .. image-sg:: /gallery/event_handling/images/sphx_glr_zoom_window_002.png :alt: Zoom window :srcset: /gallery/event_handling/images/sphx_glr_zoom_window_002.png, /gallery/event_handling/images/sphx_glr_zoom_window_002_2_00x.png 2.00x :class: sphx-glr-multi-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np # Fixing random state for reproducibility np.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 *= 200 axsrc.scatter(x, y, s, c) axzoom.scatter(x, y, s, c) def on_press(event): if event.button != 1: return x, y = event.xdata, event.ydata axzoom.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() .. _sphx_glr_download_gallery_event_handling_zoom_window.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: zoom_window.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: zoom_window.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_