GenericMappingTools / GenericMappingTools/pygmt

pygmt.config() does not apply FONT_ANNOT_PRIMARY when called before Figure() on PyGMT 0.18.0 / GMT 6.6.0

Open
#4,732 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
874
Forks
255
Avg merge
1d 21h
Merged PRs (30d)
40

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

```text
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)

```python
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)

```python
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,

```python
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.

```bash
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

```python

```

### Full error message

```python-traceback

```

### System information

```bash
❯ 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
```

Contributor guide

Open the contributing guide

Research direction

Start with the reported minimal examples using pygmt.config(), Figure(), and fig.basemap(), comparing the order in which the configuration context and figure are created. Trace the initialization behavior behind those entry points and add a regression test showing that FONT_ANNOT_PRIMARY applies in both orders; done means both examples produce the configured annotation styling.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design, data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.