Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0d3425a

Browse filesBrowse files
committed
DOC: add inset axes example
1 parent cebac4f commit 0d3425a
Copy full SHA for 0d3425a

File tree

Expand file treeCollapse file tree

1 file changed

+59
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+59
-0
lines changed
+59Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""
2+
======================
3+
Zoom region inset axes
4+
======================
5+
6+
Example of an inset axes and a rectangle showing where the zoom is located.
7+
8+
"""
9+
10+
import matplotlib.pyplot as plt
11+
import numpy as np
12+
13+
def get_demo_image():
14+
from matplotlib.cbook import get_sample_data
15+
import numpy as np
16+
f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
17+
z = np.load(f)
18+
# z is a numpy array of 15x15
19+
return z, (-3, 4, -4, 3)
20+
21+
fig, ax = plt.subplots(figsize=[5, 4])
22+
23+
# make data
24+
Z, extent = get_demo_image()
25+
Z2 = np.zeros([150, 150], dtype="d")
26+
ny, nx = Z.shape
27+
Z2[30:30 + ny, 30:30 + nx] = Z
28+
29+
ax.imshow(Z2, extent=extent, interpolation="nearest",
30+
origin="lower")
31+
32+
# inset axes....
33+
axins = ax.inset_axes([0.5, 0.5, 0.47, 0.47])
34+
axins.imshow(Z2, extent=extent, interpolation="nearest",
35+
origin="lower")
36+
# sub region of the original image
37+
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
38+
axins.set_xlim(x1, x2)
39+
axins.set_ylim(y1, y2)
40+
axins.set_xticklabels('')
41+
axins.set_yticklabels('')
42+
43+
ax.zoom_inset_rectangle(axins)
44+
45+
plt.show()
46+
47+
#############################################################################
48+
#
49+
# ------------
50+
#
51+
# References
52+
# """"""""""
53+
#
54+
# The use of the following functions and methods is shown in this example:
55+
56+
import matplotlib
57+
matplotlib.axes.Axes.inset_axes
58+
matplotlib.axes.Axes.zoom_inset_rectangle
59+
matplotlib.axes.Axes.imshow

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.