Skip to content

Commit 64a34d2

Browse files
seismanweiji14
andauthored
Let Figure.savefig support filenames with spaces (#1116)
Co-authored-by: Wei Ji <[email protected]>
1 parent 223032d commit 64a34d2

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pygmt/figure.py

+2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ def psconvert(self, **kwargs):
190190
# Default cropping the figure to True
191191
if "A" not in kwargs:
192192
kwargs["A"] = ""
193+
# allow for spaces in figure name
194+
kwargs["F"] = f'"{kwargs.get("F")}"' if kwargs.get("F") else None
193195
with Session() as lib:
194196
lib.call_module("psconvert", build_arg_string(kwargs))
195197

pygmt/tests/test_figure.py

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111
from pygmt import Figure, set_display
1212
from pygmt.exceptions import GMTInvalidInput
13+
from pygmt.helpers import GMTTempFile
1314

1415

1516
def test_figure_region():
@@ -107,6 +108,17 @@ def test_figure_savefig_transparent():
107108
os.remove(fname)
108109

109110

111+
def test_figure_savefig_filename_with_spaces():
112+
"""
113+
Check if savefig (or psconvert) supports filenames with spaces.
114+
"""
115+
fig = Figure()
116+
fig.basemap(region=[0, 1, 0, 1], projection="X1c/1c", frame=True)
117+
with GMTTempFile(prefix="pygmt-filename with spaces", suffix=".png") as imgfile:
118+
fig.savefig(imgfile.name)
119+
assert os.path.exists(imgfile.name)
120+
121+
110122
def test_figure_savefig():
111123
"""
112124
Check if the arguments being passed to psconvert are correct.

0 commit comments

Comments
 (0)