Description of the problem
Description
I found an unexpected behavior of pygmt.config() when changing GMT font settings.
The configuration works if pygmt.config() is called after creating a Figure, but it is ignored if called before Figure().
This behavior differs from what I expected and from GMT command-line behavior.
Environment
PyGMT v0.18.0
GMT 6.6.0
Python 3.14.3
macOS 26.5.1 (Apple Silicon)
PyGMT information:
version: v0.18.0
GMT library information:
version: 6.6.0
Reproducible example
Case 1 (configuration ignored)
import pygmt
with pygmt.config(FONT_ANNOT_PRIMARY="32p,Courier,blue"):
fig = pygmt.Figure()
fig.basemap(
region=[0,1,0,1],
projection="X10c",
frame="af",
)
fig.show()
Result:
- annotation color remains black
- annotation font remains default
Case 2 (works)
import pygmt
fig = pygmt.Figure()
with pygmt.config(FONT_ANNOT_PRIMARY="32p,Courier,blue"):
fig.basemap(
region=[0,1,0,1],
projection="X10c",
frame="af",
)
fig.show()
Result:
- annotation becomes blue
- font changes correctly
Verification
Inside the first example,
with pygmt.config(FONT_ANNOT_PRIMARY="32p,Courier,blue"):
import subprocess
subprocess.run(["gmt", "get", "FONT_ANNOT_PRIMARY"])
prints
so the configuration appears to be set.
GMT command line
The equivalent GMT command works correctly.
gmt begin test pdf
gmt set FONT_ANNOT_PRIMARY 32p,Courier,blue
gmt basemap -R0/1/0/1 -JX10c -Baf
gmt end show
The annotations are blue as expected.
Expected behavior
I expected both examples to produce identical figures because
pygmt.config() should configure the GMT session regardless of whether
Figure() has already been created.
Actual behavior
The configuration only takes effect if Figure() is created before entering the pygmt.config() context.
Question
Is this intended behavior due to how GMT modern-mode sessions are initialized, or is this a PyGMT bug?
Minimal Complete Verifiable Example
Full error message
System information
❯ python -c "import pygmt; pygmt.show_versions()"
PyGMT information:
version: v0.18.0
System information:
python: 3.14.3 (v3.14.3:323c59a5e34, Feb 3 2026, 11:41:37) [Clang 16.0.0 (clang-1600.0.26.6)]
executable: /usr/local/bin/python
machine: macOS-26.5.1-arm64-arm-64bit-Mach-O
Dependency information:
numpy: 2.2.6
pandas: 2.3.3
xarray: 2025.7.1
packaging: 26.0
contextily: 1.7.0
geopandas: 1.1.2
IPython: 9.10.0
pyarrow: 23.0.1
rioxarray: 0.21.0
gdal: 3.13.0
ghostscript: 10.07.0
GMT library information:
version: 6.6.0
padding: 2
share dir: /usr/local/Cellar/gmt-6.6.0/share
plugin dir: /usr/local/Cellar/gmt-6.6.0/lib/gmt/plugins
library path: /usr/local/Cellar/gmt-6.6.0/lib/libgmt.dylib
cores: 8
grid layout: rows
image layout:
binary version: 6.6.0
Description of the problem
Description
I found an unexpected behavior of
pygmt.config()when changing GMT font settings.The configuration works if
pygmt.config()is called after creating aFigure, but it is ignored if called beforeFigure().This behavior differs from what I expected and from GMT command-line behavior.
Environment
Reproducible example
Case 1 (configuration ignored)
Result:
Case 2 (works)
Result:
Verification
Inside the first example,
prints
so the configuration appears to be set.
GMT command line
The equivalent GMT command works correctly.
The annotations are blue as expected.
Expected behavior
I expected both examples to produce identical figures because
pygmt.config()should configure the GMT session regardless of whetherFigure()has already been created.Actual behavior
The configuration only takes effect if
Figure()is created before entering thepygmt.config()context.Question
Is this intended behavior due to how GMT modern-mode sessions are initialized, or is this a PyGMT bug?
Minimal Complete Verifiable Example
Full error message
System information
❯ python -c "import pygmt; pygmt.show_versions()" PyGMT information: version: v0.18.0 System information: python: 3.14.3 (v3.14.3:323c59a5e34, Feb 3 2026, 11:41:37) [Clang 16.0.0 (clang-1600.0.26.6)] executable: /usr/local/bin/python machine: macOS-26.5.1-arm64-arm-64bit-Mach-O Dependency information: numpy: 2.2.6 pandas: 2.3.3 xarray: 2025.7.1 packaging: 26.0 contextily: 1.7.0 geopandas: 1.1.2 IPython: 9.10.0 pyarrow: 23.0.1 rioxarray: 0.21.0 gdal: 3.13.0 ghostscript: 10.07.0 GMT library information: version: 6.6.0 padding: 2 share dir: /usr/local/Cellar/gmt-6.6.0/share plugin dir: /usr/local/Cellar/gmt-6.6.0/lib/gmt/plugins library path: /usr/local/Cellar/gmt-6.6.0/lib/libgmt.dylib cores: 8 grid layout: rows image layout: binary version: 6.6.0