@@ -257,12 +257,18 @@ def savefig(
257
257
"""
258
258
Save the figure to a file.
259
259
260
- This method implements a matplotlib-like interface for
261
- :meth:`pygmt.Figure.psconvert`.
260
+ Supported file formats and their extensions:
262
261
263
- Supported formats: PNG (``.png``), JPEG (``.jpg`` or ``.jpeg``),
264
- PDF (``.pdf``), BMP (``.bmp``), TIFF (``.tif``), EPS (``.eps``), and
265
- KML (``.kml``). The KML output generates a companion PNG file.
262
+ - PNG (``.png``)
263
+ - JPEG (``.jpg`` or ``.jpeg``)
264
+ - PDF (``.pdf``)
265
+ - BMP (``.bmp``)
266
+ - TIFF (``.tif``)
267
+ - GeoTIFF (``.tiff``)
268
+ - EPS (``.eps``)
269
+ - KML (``.kml``)
270
+
271
+ For KML format, a companion PNG file is also generated.
266
272
267
273
You can pass in any keyword arguments that
268
274
:meth:`pygmt.Figure.psconvert` accepts.
@@ -279,10 +285,10 @@ def savefig(
279
285
If ``True``, will crop the figure canvas (page) to the plot area.
280
286
anti_alias: bool
281
287
If ``True``, will use anti-aliasing when creating raster images
282
- (PNG, JPG , TIFF). More specifically, it passes arguments ``t2``
283
- and ``g2 `` to the ``anti_aliasing`` parameter of
284
- :meth:`pygmt.Figure.psconvert`. Ignored if creating vector
285
- graphics.
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.
286
292
show: bool
287
293
If ``True``, will open the figure in an external viewer.
288
294
dpi : int
@@ -301,15 +307,20 @@ def savefig(
301
307
"bmp" : "b" ,
302
308
"eps" : "e" ,
303
309
"tif" : "t" ,
310
+ "tiff" : None , # GeoTIFF doesn't need the -T option
304
311
"kml" : "g" ,
305
312
}
306
313
307
314
fname = Path (fname )
308
315
prefix , suffix = fname .with_suffix ("" ).as_posix (), fname .suffix
309
316
ext = suffix [1 :].lower () # Remove the . and normalize to lowercase
310
- # alias jpeg to jpg
311
- if ext == "jpeg" :
317
+
318
+ if ext == "jpeg" : # Alias jpeg to jpg
312
319
ext = "jpg"
320
+ elif ext == "tiff" : # GeoTIFF
321
+ kwargs ["W" ] = "+g"
322
+ elif ext == "kml" : # KML
323
+ kwargs ["W" ] = "+k"
313
324
314
325
if ext not in fmts :
315
326
if ext == "ps" :
@@ -328,11 +339,15 @@ def savefig(
328
339
if anti_alias :
329
340
kwargs ["Qt" ] = 2
330
341
kwargs ["Qg" ] = 2
331
- if ext == "kml" :
332
- kwargs ["W" ] = "+k"
333
342
334
343
self .psconvert (prefix = prefix , fmt = fmt , crop = crop , ** kwargs )
335
344
345
+ # Remove the .pgw world file if exists
346
+ # Not necessary after GMT 6.5.0.
347
+ # See upstream fix https://github.com/GenericMappingTools/gmt/pull/7865
348
+ if ext == "tiff" and fname .with_suffix (".pgw" ).exists ():
349
+ fname .with_suffix (".pgw" ).unlink ()
350
+
336
351
# Rename if file extension doesn't match the input file suffix
337
352
if ext != suffix [1 :]:
338
353
fname .with_suffix ("." + ext ).rename (fname )
0 commit comments