This is my code:
grid = pygmt.datasets.load_earth_relief(resolution="30s", region=region)
fig = pygmt.Figure()
fig.grdimage(grid=grid, projection="M15c", frame="a", cmap="geo")
#fig.colorbar(frame=["a1000", "x+lElevation", "y+lm"])
fig.colorbar(
cmap="geo",
# Colorbar position justified outside map frame (J) at Middle Right (MR),
# offset (+o) by 1 cm horizontally and 0 cm vertically from anchor point,
# with a length/width (+w) of 7 cm by 0.5 cm and a box for NaN values (+n)
position="JMR+o1.1c/0c+w7c/0.5c+n+mc",
#position="JMR+o1c/0c+w7c/0.5c+n+mc",
# Note that the label 'Elevation' is moved to the opposite side and plotted
# vertically as a column of text using '+mc' in the position parameter
# above
frame=["x+lElevation", "y+lm"],
scale=10,
)
pygmt.makecpt(cmap="viridis", series=[min(mag), max(mag)])
# style='c0.1i',
fig.plot(x=lon,
y=lat,
sizes=0.02 * 2 ** mag,## 少输入's'坑很久!
color=mag,
cmap=True,
style='cc',
pen='black',
# label='Eq',
)
fig.colorbar(frame='af+l"Depth (km)"')
# fig.legend(position="JTR+jTR+o0.2c", box=True)
with fig.inset(position="jBL+w5c+o0.5c/0.2c", box="+pblack"):
# Use a plotting function to create a figure inside the inset
fig.coast(
region=[80,110,20,40],
projection="M5c",
land="gray",
borders=[1, 2],
shorelines="1/thin",
water="white",
# Use dcw to selectively highlight an area
dcw="US.MA+gred",
)
rectangle = [[100,32,107,38]] #顺序不一样
fig.plot(data=rectangle, style="r+s", pen="2p,blue")
fig.show()
And the pic out is like this: