绘制地形

利用 pygmt.Figure.grdimage() 绘制地形。

注解

可结合《绘制地形起伏》和《earth_relief: 全球地形起伏数据》学习。

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

import pygmt
grid = pygmt.datasets.load_earth_relief(resolution="30m")

Out:

gmtwhich [NOTICE]: Remote data courtesy of GMT data server OCEANIA [https://oceania.generic-mapping-tools.org]
gmtwhich [NOTICE]: Earth Relief at 30x30 arc minutes from Gaussian Cartesian filtering (55 km fullwidth) of SRTM15+V2.1 [Tozer et al., 2019].
gmtwhich [NOTICE]:   -> Download grid file [395K]: earth_relief_30m_p.grd

利用 pygmt.Figure.grdimage() 读取网格文件后绘制地形图,默认采用等距圆柱投影和 turbo 颜色表。

fig = pygmt.Figure()
fig.grdimage(grid=grid)
fig.show()
plot 13 earth relief

Out:

<IPython.core.display.Image object>

可以修改投影方式和颜色表:

fig = pygmt.Figure()
fig.grdimage(grid=grid, projection="R12c", cmap="geo")
fig.show()
plot 13 earth relief

Out:

<IPython.core.display.Image object>

添加 colorbar:

fig = pygmt.Figure()
fig.grdimage(grid=grid, projection="R12c", cmap="relief")
fig.colorbar(frame=["a2500", "x+lElevation", "y+lm"])
fig.show()
plot 13 earth relief

Out:

<IPython.core.display.Image object>

绘制局部区域:

grid = pygmt.datasets.load_earth_relief(resolution="05m", region=[-14, 30, 35, 60])
fig = pygmt.Figure()
fig.grdimage(grid=grid, projection="M15c", frame="a", cmap="geo")
fig.colorbar(frame=["a1000", "x+lElevation", "y+lm"])
fig.show()
plot 13 earth relief

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): S90E000

<IPython.core.display.Image object>

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

Gallery generated by Sphinx-Gallery