GeezerVison is showing github.com — PS_CONVERT has no effect when using Figure.show/Figure.savefig/Figure.psconvert · Issue #4256 · GenericMappingTools/pygmt
PS_CONVERT has no effect when using Figure.show/Figure.savefig/Figure.psconvert #4256DescriptionDescription of the problem
PS_CONVERT is a GMT configuration parameter that can store a comma-separate list of options to use when calling psconvert implicitely when gmt end is called. The GMT documentation is at https://docs.generic-mapping-tools.org/6.6/gmt.conf.html#term-PS_CONVERT.
Comma-separated list of optional module arguments that we should supply when psconvert is called implicitly under modern mode [A]. Ignored when psconvert is called on the command line explicitly. The option arguments must be listed without their leading option hyphen.
In PyGMT, Figure.show/Figure.savefig calls psconvert internally, so this option has no effect, which is expected according to the GMT documentation. As a workaround, we can explicitely add these options when calling Figure.show/Figure.savefig, but it's a little tedious.
Possible solutions are:
- Document that
PS_CONVERT is ignored in PyGMT.
- In
Figure.psconvert, parse the values of PS_CONVERT and append them to the argument list when calling psconvert.
- Thinking about if there is a more Pythonic and elegant way to implement the same feature.
Solution 2 is not that hard to implement, but need time to think about solution 3.
Minimal Complete Verifiable Example
import pygmt
pygmt.config(PS_CONVERT="C-I/home/xxx/.gmt")
fig = pygmt.Figure()
fig.basemap(region="g", projection="H8c", frame=True)
fig.savefig("map.png", verbose="d")
Full error message
pygmt-session [DEBUG]: Revised options: -A -Fmap -Qg2 -Qt2 -Tg -Vd
psconvert [DEBUG]: Ghostscript executable full name:
psconvert [DEBUG]: gmt_run_process_get_first_line: Pass to popen: [gs --version 2> /dev/null]
psconvert [DEBUG]: gs --version 2> /dev/null was successful
psconvert [DEBUG]: Ghostscript version: 10.06.0
Options in PS_CONVERT are not shown in the first line of the debugging message.
The bug was originally found in #3220. Activityseisman commented on Jan 12, 2026 Thanks @Chuan1937 for tackling this in PR #4342.
After comparing Solutions 1 and 2, I prefer Solution 1.
The argument of PS_CONVERT (e.g., pygmt.config(PS_CONVERT="C-I/home/xxx/.gmt,E300") is not readable and not Pythonic. Users have to read through the GMT documentation to understand its meaning. It also changes the global configuration, which may have side-effect.
Instead of setting PS_CONVERT, user can set parameters when calling Figure.savefig/Figure.show, which is more readable and Pythonic:
fig.savefig("map.png", gs_option="-I/home/xxx/.gmt", dpi=300)
If the same parameters need to be reused, it's easy to define a dict and pass it to Figure.savefig/Figure.show when needed. E.g.,
psconvert_kwdict = dict(gs_option="-I/home/xxx/.gmt", dpi=300)
fig.savefig("map1.png", **psconvert_kwdict)
fig.show(**psconvert_kwdict)seisman commented on Jan 13, 2026 @GenericMappingTools/pygmt-maintainers Any comments? weiji14 commented on Jan 13, 2026
fig.savefig("map.png", gs_option="-I/home/xxx/.gmt", dpi=300)
Using gs_option (i.e. -C in psconvert) sounds reasonable. Maybe we can also remove or comment out PS_CONVERT from the autocomplete at
so that people don't use it accidentally? Or is there a way still to make the PS_CONVERT config work if used globally? seisman commented on Jan 13, 2026
Using gs_option (i.e. -C in psconvert) sounds reasonable. Maybe we can also remove or comment out PS_CONVERT from the autocomplete at so that people don't use it accidentally?
With Solution 1, I think we should do:
Or is there a way still to make the PS_CONVERT config work if used globally?
In GMT CLI, PS_CONVERT is only used when calling gmt end. To make it work in PyGMT, we have to parse the value of PS_CONVERT and pass the CLI options psconvert when calling Figure.savefig/Figure.show. See the initial version in PR #4342
|
# Check PS_CONVERT settings: PyGMT calls psconvert explicitly, |
|
# so inject default options here if the user didn't override them. |
|
if ps_convert_config := lib.get_default("PS_CONVERT"): |
|
for option in ps_convert_config.split(","): |
|
opt = option.strip() |
|
if not opt: |
|
continue |
|
# Validate option format: expect a single-character flag followed |
|
# by an optional value (e.g., "A", "E300"). |
|
if not opt[0].isalpha(): |
|
raise GMTValueError( |
|
opt, |
|
description="PS_CONVERT option", |
|
reason=( |
|
"Invalid PS_CONVERT configuration: each option must " |
|
"start with a letter flag followed by an optional value." |
|
), |
|
) |
|
flag, value = opt[0], opt[1:] |
|
if flag not in aliasdict: |
|
aliasdict[flag] = value |
weiji14 commented on Jan 13, 2026
In GMT CLI, PS_CONVERT is only used when calling gmt end. To make it work in PyGMT, we have to parse the value of PS_CONVERT and pass the CLI options psconvert when calling Figure.savefig/Figure.show. See the initial version in PR #4342
This chunk of code is a little trickier to understand/maintain. So would lean towards just raising a warning when PS_CONVERT is used as you suggested ^.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|