import pygmt
# 加载地形数据
grid_data = pygmt.datasets.load_earth_relief(
resolution='01m',
region = [117, 133, 23, 35]
)
gradient_data = pygmt.grdgradient(
grid = grid_data,
azimuth = [30, 125],
normalize = 'e0.7'
)
fig = pygmt.Figure()
# 地理底图
pygmt.makecpt(
cmap = 'geo',
)
# 高程处理
fig.grdimage(
projection = 'M25c',
region = [117, 133, 23, 35],
grid = grid_data,
shading = gradient_data
)
# 画海岸线和给海上色
fig.coast(
area_thresh = '100',
water = 'black@80',
)
# 画一个白色的比例尺背景,大小位置自己调
fig.plot(
data = [[125, 24], [131,24], [131,25.5], [125,25.5]],
fill = 'white',
transparency = 20,
straight_line = True
)
# 比例尺
fig.coast(
area_thresh = '100',
map_scale = '128/25/25/500',
shorelines = 'faint,black',
frame = ['WSen', 'xaf', 'yaf']
)
fig.show()
最后效果如图