Skip to content

Commit aff5db7

Browse files
core-manweiji14seismanmichaelgrund
authored
Add a gallery example of inset map showing a rectangle region (#1020)
Co-authored-by: Wei Ji <[email protected]> Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Michael Grund <[email protected]>
1 parent a8a8781 commit aff5db7

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Inset map showing a rectangular region
3+
--------------------------------------
4+
5+
The :meth:`pygmt.Figure.inset` method adds an inset figure inside a larger
6+
figure. The function is called using a ``with`` statement, and its position,
7+
box, offset, and margin can be customized. Plotting methods called within the
8+
``with`` statement plot into the inset figure.
9+
"""
10+
11+
import pygmt
12+
13+
# Set the region of the main figure
14+
region = [137.5, 141, 34, 37]
15+
16+
fig = pygmt.Figure()
17+
18+
# Plot the base map of the main figure. Universal Transverse Mercator (UTM) projection
19+
# is used and the UTM zone is set to be "54S".
20+
fig.basemap(region=region, projection="U54S/12c", frame=["WSne", "af"])
21+
22+
# Set the land color to "lightbrown", the water color to "azure1", the shoreline
23+
# width to "2p", and the area threshold to 1000 km^2 for the main figure
24+
fig.coast(land="lightbrown", water="azure1", shorelines="2p", area_thresh=1000)
25+
26+
# Create an inset map, setting the position to bottom right, the width to
27+
# 3 cm, the height to 3.6 cm, and the x- and y-offsets to
28+
# 0.1 cm, respectively. Draws a rectangular box around the inset with a fill color
29+
# of "white" and a pen of "1p".
30+
with fig.inset(position="jBR+w3c/3.6c+o0.1c", box="+gwhite+p1p"):
31+
# Plot the Japan main land in the inset using coast. "U54S/M?" means UTM
32+
# projection with map width automatically determined from the inset width.
33+
# Highlight the Japan area in "lightbrown"
34+
# and draw its outline with a pen of "0.2p".
35+
fig.coast(
36+
region=[129, 146, 30, 46],
37+
projection="U54S/?",
38+
dcw="JP+glightbrown+p0.2p",
39+
area_thresh=10000,
40+
)
41+
# Plot a rectangle ("r") in the inset map to show the area of the main figure.
42+
# "+s" means that the first two columns are the longitude and latitude of
43+
# the bottom left corner of the rectangle, and the last two columns the
44+
# longitude and latitude of the uppper right corner.
45+
rectangle = [[region[0], region[2], region[1], region[3]]]
46+
fig.plot(data=rectangle, style="r+s", pen="2p,blue")
47+
48+
fig.show()

0 commit comments

Comments
 (0)