Repository navigation
Description
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
32p,Courier,blue
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 showThe 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
Activity
github-actions commentedon Jul 17, 2026
👋 Thanks for opening your first issue here!
Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.
seisman commentedon Jul 17, 2026
Hmmm, I can't reproduce your case 1, i.e., the annotation color and font work as expected for me.
Could you please add
pygmt.config(GMT_VERBOSE="debug")afterimport pygmt(for both cases 1 and 2), and then post the debugging messages?jpatiani commentedon Jul 17, 2026
Ok, that weird. Now, cases 1 and 2 give correct result. However, if I try with more complex command the behavior similar as the bug.
Here with, I copy the code with debug report.
Case 1
Debug result:
Case 2
Debug result:
yvonnefroehlich commentedon Jul 17, 2026
This is a know (long-term) issue with
pygmt.config(). Currently it only works when it is called after setting up thepygmt.Figure()instance. This is the case for both global and local changes.xref:
Maybe we should add a note to the documentation at https://www.pygmt.org/v0.19.0/api/generated/pygmt.config.html until we have a fix for this.
seisman commentedon Jul 19, 2026
@yvonnefroehlich is right. See #733 (comment) for a more detailed explanation.