Note
Go to the end to download the full example code.
Zoom region inset Axes#
Example of an inset Axes and a rectangle showing where the zoom is located.
import numpy as np
from matplotlib import cbook
from matplotlib import pyplot as plt
fig, ax = plt.subplots()
# make data
Z = cbook.get_sample_data("axes_grid/bivariate_normal.npy") # 15x15 array
Z2 = np.zeros((150, 150))
ny, nx = Z.shape
Z2[30:30+ny, 30:30+nx] = Z
extent = (-3, 4, -4, 3)
ax.imshow(Z2, extent=extent, origin="lower")
# inset Axes....
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9 # subregion of the original image
axins = ax.inset_axes(
[0.5, 0.5, 0.47, 0.47],
xlim=(x1, x2), ylim=(y1, y2), xticklabels=[], yticklabels=[])
axins.imshow(Z2, extent=extent, origin="lower")
ax.indicate_inset_zoom(axins, edgecolor="black")
plt.show()
References
The use of the following functions, methods, classes and modules is shown in this example: