Skip to content

PS_CONVERT has no effect when using Figure.show/Figure.savefig/Figure.psconvert #4256

Closed

Description

@seisman

Description 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:

  1. Document that PS_CONVERT is ignored in PyGMT.
  2. In Figure.psconvert, parse the values of PS_CONVERT and append them to the argument list when calling psconvert.
  3. 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.

Activity

  1. added
    bug
    on Dec 8, 2025
  2. added
    bug
    and removed
    bug
    on Jan 12, 2026
  3. seisman commented on Jan 12, 2026

    @seisman
    MemberAuthor

    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)
  4. seisman commented on Jan 13, 2026

    @seisman
    MemberAuthor

    @GenericMappingTools/pygmt-maintainers Any comments?

  5. added this to the 0.19.0 milestone on Jan 13, 2026
  6. weiji14 commented on Jan 13, 2026

    @weiji14
    Member

    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

    "PS_CONVERT",

    so that people don't use it accidentally? Or is there a way still to make the PS_CONVERT config work if used globally?

  7. seisman commented on Jan 13, 2026

    @seisman
    MemberAuthor

    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

  8. weiji14 commented on Jan 13, 2026

    @weiji14
    Member

    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 ^.

  9. added
    enhancement
    and removed
    bug
    on Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions