diff --git a/pygmt/figure.py b/pygmt/figure.py index e5b5cbf7184..09b5b4645d1 100644 --- a/pygmt/figure.py +++ b/pygmt/figure.py @@ -255,20 +255,27 @@ def savefig( self, fname, transparent=False, crop=True, anti_alias=True, show=False, **kwargs ): """ - Save the figure to a file. + Save the figure to an image file. - Supported file formats and their extensions: + Supported image formats and their extensions: + + **Raster image formats** - - PNG (``.png``) - - JPEG (``.jpg`` or ``.jpeg``) - - PDF (``.pdf``) - BMP (``.bmp``) - - TIFF (``.tif``) + - JPEG (``.jpg`` or ``.jpeg``) - GeoTIFF (``.tiff``) + - PNG (``.png``) + - PPM (``.ppm``) + - TIFF (``.tif``) + + **Vector image formats** + - EPS (``.eps``) - - KML (``.kml``) + - PDF (``.pdf``) - For KML format, a companion PNG file is also generated. + Beside the above formats, you can also save the figure to a KML file + (``.kml``), with a companion PNG file generated automatically. The KML + file can be viewed in Google Earth. You can pass in any keyword arguments that :meth:`pygmt.Figure.psconvert` accepts. @@ -284,11 +291,10 @@ def savefig( crop : bool If ``True``, will crop the figure canvas (page) to the plot area. anti_alias: bool - If ``True``, will use anti-aliasing when creating raster images - (BMP, PNG, JPEG, TIFF, and GeoTIFF). More specifically, it passes - the arguments ``"t2"`` and ``"g2"`` to the ``anti_aliasing`` - parameter of :meth:`pygmt.Figure.psconvert`. Ignored if creating - vector graphics. + If ``True``, will use anti-aliasing when creating raster images. + More specifically, it passes the arguments ``"t2"`` and ``"g2"`` + to the ``anti_aliasing`` parameter of + :meth:`pygmt.Figure.psconvert`. Ignored if creating vector images. show: bool If ``True``, will open the figure in an external viewer. dpi : int @@ -301,14 +307,15 @@ def savefig( """ # All supported formats fmts = { - "png": "g", - "pdf": "f", - "jpg": "j", "bmp": "b", "eps": "e", + "jpg": "j", + "kml": "g", + "pdf": "f", + "png": "g", + "ppm": "m", "tif": "t", "tiff": None, # GeoTIFF doesn't need the -T option - "kml": "g", } fname = Path(fname) diff --git a/pygmt/tests/test_figure.py b/pygmt/tests/test_figure.py index 4969aad0fb0..95d2241fa35 100644 --- a/pygmt/tests/test_figure.py +++ b/pygmt/tests/test_figure.py @@ -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 jpeg bmp eps tif PNG JPG JPEG Png".split(): + for fmt in "bmp eps jpg jpeg pdf png ppm tif PNG JPG JPEG Png".split(): fname = ".".join([prefix, fmt]) fig.savefig(fname)