Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ def savefig(
This method implements a matplotlib-like interface for
:meth:`pygmt.Figure.psconvert`.

Supported formats: PNG (``.png``), JPEG (``.jpg``), PDF (``.pdf``),
BMP (``.bmp``), TIFF (``.tif``), EPS (``.eps``), and KML (``.kml``).
The KML output generates a companion PNG file.
Supported formats: PNG (``.png``), JPEG (``.jpg`` or ``.jpeg),
PDF (``.pdf``), BMP (``.bmp``), TIFF (``.tif``), EPS (``.eps``), and
KML (``.kml``). The KML output generates a companion PNG file.

You can pass in any keyword arguments that
:meth:`pygmt.Figure.psconvert` accepts.
Expand Down Expand Up @@ -298,14 +298,15 @@ def savefig(
"png": "g",
"pdf": "f",
"jpg": "j",
"jpeg": "j",
"bmp": "b",
"eps": "e",
"tif": "t",
"kml": "g",
}

prefix, ext = os.path.splitext(fname)
ext = ext[1:] # Remove the .
prefix = Path(fname).with_suffix("").as_posix()
ext = Path(fname).suffix[1:] # suffix without .
if ext not in fmts:
if ext == "ps":
raise GMTInvalidInput(
Expand All @@ -327,6 +328,11 @@ def savefig(
kwargs["W"] = "+k"

self.psconvert(prefix=prefix, fmt=fmt, crop=crop, **kwargs)

# rename .jpg to .jpeg
if ext == "jpeg":
Path(fname).with_suffix(".jpg").rename(fname)

if show:
launch_external_viewer(fname)

Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_figure_savefig_exists():
fig = Figure()
fig.basemap(region="10/70/-300/800", projection="X3i/5i", frame="af")
prefix = "test_figure_savefig_exists"
for fmt in "png pdf jpg bmp eps tif".split():
for fmt in "png pdf jpg jpeg bmp eps tif".split():
fname = ".".join([prefix, fmt])
fig.savefig(fname)
assert os.path.exists(fname)
Expand Down