绘制等高线

利用 pygmt.Figure.grdcontour() 绘制等高线。

绘制等高线

首先利用 pygmt.datasets.load_earth_relief() 从 GMT 服务器读取地形数据:

import pygmt
grid = pygmt.datasets.load_earth_relief(resolution="05m", region=[-92.5, -82.5, -3, 7])

Out:

grdblend [NOTICE]: Remote data courtesy of GMT data server OCEANIA [https://oceania.generic-mapping-tools.org]
grdblend [NOTICE]: Earth Relief at 5x5 arc minutes from Gaussian Cartesian filtering (9 km fullwidth) of SRTM15+V2.1 [Tozer et al., 2019].
grdblend [NOTICE]:   -> Download 180x180 degree grid tile (earth_relief_05m_p): S90W180

pygmt.Figure.grdcontour() 读取网格文件后,会同时绘制有标注的等高线和无标注的等高线。在下例中,等高线间距为 500m,每 1000m 进行注释,默认采用等距圆柱投影:

fig = pygmt.Figure()
fig.grdcontour(grid=grid)  # 地形网格文件
fig.show()
plot 12 contour

Out:

<IPython.core.display.Image object>

设置等高线

fig = pygmt.Figure()
fig.grdcontour(
    annotation=1000,  # 等高线标注间隔
    interval=250,  # 等高线绘制间隔
    grid=grid,
    limit=[-4000, -2000],  # 等高线绘制区间
    projection="M10c",  # 设置投影方式
    frame=True,  # 显示边框
)
fig.show()
plot 12 contour

Out:

<IPython.core.display.Image object>

添加地形彩图

pygmt.Figure.grdimage() 可以为 pygmt.Figure.grdcontour() 添加地形彩图,学习《理解图层》后可以知道必须先绘制地形彩图,再绘制等高线。

fig = pygmt.Figure()
fig.grdimage(
    grid=grid,
    cmap="haxby",
    projection="M10c",
    frame=True,
)
fig.grdcontour(
    annotation=1000,
    interval=250,
    grid=grid,
    limit=[-4000, -2000],
)
fig.show()
plot 12 contour

Out:

<IPython.core.display.Image object>

Total running time of the script: ( 0 minutes 7.577 seconds)

Gallery generated by Sphinx-Gallery