diff --git a/pygmt/figure.py b/pygmt/figure.py index 621f747127d..5b7a2a3cf3b 100644 --- a/pygmt/figure.py +++ b/pygmt/figure.py @@ -192,8 +192,13 @@ def psconvert(self, **kwargs): # Default cropping the figure to True if "A" not in kwargs: kwargs["A"] = "" + # Manually handle prefix -F argument so spaces aren't converted to \040 + # by build_arg_string function. For more information, see + # https://github.com/GenericMappingTools/pygmt/pull/1487 + prefix = kwargs.pop("F") + with Session() as lib: - lib.call_module("psconvert", build_arg_string(kwargs)) + lib.call_module("psconvert", f'-F"{prefix}" {build_arg_string(kwargs)}') def savefig( self, fname, transparent=False, crop=True, anti_alias=True, show=False, **kwargs diff --git a/pygmt/tests/test_figure.py b/pygmt/tests/test_figure.py index 3c77b146faa..73b907dfee5 100644 --- a/pygmt/tests/test_figure.py +++ b/pygmt/tests/test_figure.py @@ -138,7 +138,7 @@ def test_figure_savefig_filename_with_spaces(): fig = Figure() fig.basemap(region=[0, 1, 0, 1], projection="X1c/1c", frame=True) with GMTTempFile(prefix="pygmt-filename with spaces", suffix=".png") as imgfile: - fig.savefig(imgfile.name) + fig.savefig(fname=imgfile.name) assert r"\040" not in os.path.abspath(imgfile.name) assert os.path.exists(imgfile.name)