Skip to content

Commit 6cc61d3

Browse files
authored
Figure.savefig: Support saving figures in PPM (.ppm) format (#2771)
* Figure.savefig: Support PPM (.ppm) format * Sort formats alphabetically * Improve the docstrings to clarify raster and vector image formats
1 parent f828bc5 commit 6cc61d3

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

pygmt/figure.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -255,20 +255,27 @@ def savefig(
255255
self, fname, transparent=False, crop=True, anti_alias=True, show=False, **kwargs
256256
):
257257
"""
258-
Save the figure to a file.
258+
Save the figure to an image file.
259259
260-
Supported file formats and their extensions:
260+
Supported image formats and their extensions:
261+
262+
**Raster image formats**
261263
262-
- PNG (``.png``)
263-
- JPEG (``.jpg`` or ``.jpeg``)
264-
- PDF (``.pdf``)
265264
- BMP (``.bmp``)
266-
- TIFF (``.tif``)
265+
- JPEG (``.jpg`` or ``.jpeg``)
267266
- GeoTIFF (``.tiff``)
267+
- PNG (``.png``)
268+
- PPM (``.ppm``)
269+
- TIFF (``.tif``)
270+
271+
**Vector image formats**
272+
268273
- EPS (``.eps``)
269-
- KML (``.kml``)
274+
- PDF (``.pdf``)
270275
271-
For KML format, a companion PNG file is also generated.
276+
Beside the above formats, you can also save the figure to a KML file
277+
(``.kml``), with a companion PNG file generated automatically. The KML
278+
file can be viewed in Google Earth.
272279
273280
You can pass in any keyword arguments that
274281
:meth:`pygmt.Figure.psconvert` accepts.
@@ -284,11 +291,10 @@ def savefig(
284291
crop : bool
285292
If ``True``, will crop the figure canvas (page) to the plot area.
286293
anti_alias: bool
287-
If ``True``, will use anti-aliasing when creating raster images
288-
(BMP, PNG, JPEG, TIFF, and GeoTIFF). More specifically, it passes
289-
the arguments ``"t2"`` and ``"g2"`` to the ``anti_aliasing``
290-
parameter of :meth:`pygmt.Figure.psconvert`. Ignored if creating
291-
vector graphics.
294+
If ``True``, will use anti-aliasing when creating raster images.
295+
More specifically, it passes the arguments ``"t2"`` and ``"g2"``
296+
to the ``anti_aliasing`` parameter of
297+
:meth:`pygmt.Figure.psconvert`. Ignored if creating vector images.
292298
show: bool
293299
If ``True``, will open the figure in an external viewer.
294300
dpi : int
@@ -301,14 +307,15 @@ def savefig(
301307
"""
302308
# All supported formats
303309
fmts = {
304-
"png": "g",
305-
"pdf": "f",
306-
"jpg": "j",
307310
"bmp": "b",
308311
"eps": "e",
312+
"jpg": "j",
313+
"kml": "g",
314+
"pdf": "f",
315+
"png": "g",
316+
"ppm": "m",
309317
"tif": "t",
310318
"tiff": None, # GeoTIFF doesn't need the -T option
311-
"kml": "g",
312319
}
313320

314321
fname = Path(fname)

pygmt/tests/test_figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_figure_savefig_exists():
8383
fig = Figure()
8484
fig.basemap(region="10/70/-300/800", projection="X3i/5i", frame="af")
8585
prefix = "test_figure_savefig_exists"
86-
for fmt in "png pdf jpg jpeg bmp eps tif PNG JPG JPEG Png".split():
86+
for fmt in "bmp eps jpg jpeg pdf png ppm tif PNG JPG JPEG Png".split():
8787
fname = ".".join([prefix, fmt])
8888
fig.savefig(fname)
8989

0 commit comments

Comments
 (0)