{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Zoom modifies other Axes\n\nThis example shows how to connect events in one window, for example, a mouse\npress, to another figure window.\n\nIf you click on a point in the first window, the z and y limits of the second\nwill be adjusted so that the center of the zoom in the second window will be\nthe (x, y) coordinates of the clicked point.\n\nNote the diameter of the circles in the scatter are defined in points**2, so\ntheir size is independent of the zoom.\n\n

Note

\n\nThis example exercises the interactive capabilities of Matplotlib, and this\nwill not appear in the static documentation. Please run this code on your\nmachine to see the interactivity.\n\nYou can copy and paste individual parts, or download the entire example\nusing the link at the bottom of the page.\n\n
\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\nfigsrc, axsrc = plt.subplots(figsize=(3.7, 3.7))\nfigzoom, axzoom = plt.subplots(figsize=(3.7, 3.7))\naxsrc.set(xlim=(0, 1), ylim=(0, 1), autoscale_on=False,\n title='Click to zoom')\naxzoom.set(xlim=(0.45, 0.55), ylim=(0.4, 0.6), autoscale_on=False,\n title='Zoom window')\n\nx, y, s, c = np.random.rand(4, 200)\ns *= 200\n\naxsrc.scatter(x, y, s, c)\naxzoom.scatter(x, y, s, c)\n\n\ndef on_press(event):\n if event.button != 1:\n return\n x, y = event.xdata, event.ydata\n axzoom.set_xlim(x - 0.1, x + 0.1)\n axzoom.set_ylim(y - 0.1, y + 0.1)\n figzoom.canvas.draw()\n\nfigsrc.canvas.mpl_connect('button_press_event', on_press)\nplt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.15" } }, "nbformat": 4, "nbformat_minor": 0 }