配置参数

利用 pygmt.config 可以修改 PyGMT 的绘图参数。

注解

可结合《配置参数 》学习。

import pygmt

默认参数绘图

fig = pygmt.Figure()
fig.basemap(region=[115, 119.5, 4, 7.5], projection="M10c", frame=True)
fig.coast(land="black", water="skyblue")

fig.show()
plot 19 config

Out:

<IPython.core.display.Image object>

设置全局参数

fig = pygmt.Figure()

# 全局参数影响接下来所有的命令
pygmt.config(MAP_FRAME_TYPE="plain")
pygmt.config(FORMAT_GEO_MAP="ddd.xx")

fig.basemap(region=[115, 119.5, 4, 7.5], projection="M10c", frame=True)
fig.coast(land="black", water="skyblue")

fig.show()
plot 19 config

Out:

<IPython.core.display.Image object>

设置临时参数

fig = pygmt.Figure()

# 仅对当前命令有效,将边框设置为 fancy+
with pygmt.config(MAP_FRAME_TYPE="fancy+"):
    fig.basemap(region=[115, 119.5, 4, 7.5], projection="M10c", frame=True)
fig.coast(land="black", water="skyblue")

# 移动原点绘制下一张图
fig.shift_origin(yshift="-10c")

# 边框恢复为 fancy
fig.basemap(region=[115, 119.5, 4, 7.5], projection="M10c", frame=True)
fig.coast(land="black", water="skyblue")

fig.show()
plot 19 config

Out:

<IPython.core.display.Image object>

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

Gallery generated by Sphinx-Gallery