{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Zoom region inset Axes\n\nExample of an inset Axes and a rectangle showing where the zoom is located.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n\nfrom matplotlib import cbook\nfrom matplotlib import pyplot as plt\n\nfig, ax = plt.subplots()\n\n# make data\nZ = cbook.get_sample_data(\"axes_grid/bivariate_normal.npy\") # 15x15 array\nZ2 = np.zeros((150, 150))\nny, nx = Z.shape\nZ2[30:30+ny, 30:30+nx] = Z\nextent = (-3, 4, -4, 3)\n\nax.imshow(Z2, extent=extent, origin=\"lower\")\n\n# inset Axes....\nx1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9 # subregion of the original image\naxins = ax.inset_axes(\n [0.5, 0.5, 0.47, 0.47],\n xlim=(x1, x2), ylim=(y1, y2), xticklabels=[], yticklabels=[])\naxins.imshow(Z2, extent=extent, origin=\"lower\")\n\nax.indicate_inset_zoom(axins, edgecolor=\"black\")\n\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. admonition:: References\n\n The use of the following functions, methods, classes and modules is shown\n in this example:\n\n - `matplotlib.axes.Axes.inset_axes`\n - `matplotlib.axes.Axes.indicate_inset_zoom`\n - `matplotlib.axes.Axes.imshow`\n\n.. tags::\n\n component: axes\n plot-type: imshow\n level: intermediate\n\n" ] } ], "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.13.2" } }, "nbformat": 4, "nbformat_minor": 0 }