From 41181268488c1617e5b67d20152bbab73527ca79 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 26 Oct 2023 22:45:18 +0800 Subject: [PATCH 1/4] Figure.savefig: Support PPM (.ppm) format --- pygmt/figure.py | 2 ++ pygmt/tests/test_figure.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pygmt/figure.py b/pygmt/figure.py index e5b5cbf7184..84470c43827 100644 --- a/pygmt/figure.py +++ b/pygmt/figure.py @@ -263,6 +263,7 @@ def savefig( - JPEG (``.jpg`` or ``.jpeg``) - PDF (``.pdf``) - BMP (``.bmp``) + - PPM (``.ppm``) - TIFF (``.tif``) - GeoTIFF (``.tiff``) - EPS (``.eps``) @@ -305,6 +306,7 @@ def savefig( "pdf": "f", "jpg": "j", "bmp": "b", + "ppm": "m", "eps": "e", "tif": "t", "tiff": None, # GeoTIFF doesn't need the -T option diff --git a/pygmt/tests/test_figure.py b/pygmt/tests/test_figure.py index 4969aad0fb0..dd52462f677 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 "png pdf jpg jpeg bmp ppm eps tif PNG JPG JPEG Png".split(): fname = ".".join([prefix, fmt]) fig.savefig(fname) From ce47785bc83cf06e419cbbb5a136919379efbbaa Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 26 Oct 2023 23:08:52 +0800 Subject: [PATCH 2/4] Sort formats alphabetically --- pygmt/figure.py | 10 +++++----- pygmt/tests/test_figure.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pygmt/figure.py b/pygmt/figure.py index 84470c43827..362c8ecbe2a 100644 --- a/pygmt/figure.py +++ b/pygmt/figure.py @@ -302,15 +302,15 @@ def savefig( """ # All supported formats fmts = { - "png": "g", - "pdf": "f", - "jpg": "j", "bmp": "b", - "ppm": "m", "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 dd52462f677..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 ppm 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) From 473bef8f4354b181c0a3386b26d5b48989bc7854 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 27 Oct 2023 15:14:05 +0800 Subject: [PATCH 3/4] Fix the order of formats in docstrings --- pygmt/figure.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pygmt/figure.py b/pygmt/figure.py index 362c8ecbe2a..c8ea1e3643a 100644 --- a/pygmt/figure.py +++ b/pygmt/figure.py @@ -259,15 +259,15 @@ def savefig( Supported file formats and their extensions: - - PNG (``.png``) + - BMP (``.bmp``) + - EPS (``.eps``) + - GeoTIFF (``.tiff``) - JPEG (``.jpg`` or ``.jpeg``) + - KML (``.kml``) - PDF (``.pdf``) - - BMP (``.bmp``) + - PNG (``.png``) - PPM (``.ppm``) - TIFF (``.tif``) - - GeoTIFF (``.tiff``) - - EPS (``.eps``) - - KML (``.kml``) For KML format, a companion PNG file is also generated. From 0c8184710ea93a59ce6e3b2027114edb53e63421 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 27 Oct 2023 22:20:13 +0800 Subject: [PATCH 4/4] Improve the docstrings to clarify raster and vector image formats --- pygmt/figure.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/pygmt/figure.py b/pygmt/figure.py index c8ea1e3643a..09b5b4645d1 100644 --- a/pygmt/figure.py +++ b/pygmt/figure.py @@ -255,21 +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** - BMP (``.bmp``) - - EPS (``.eps``) - - GeoTIFF (``.tiff``) - JPEG (``.jpg`` or ``.jpeg``) - - KML (``.kml``) - - PDF (``.pdf``) + - GeoTIFF (``.tiff``) - PNG (``.png``) - PPM (``.ppm``) - TIFF (``.tif``) - For KML format, a companion PNG file is also generated. + **Vector image formats** + + - EPS (``.eps``) + - PDF (``.pdf``) + + 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. @@ -285,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