44
55import base64
66import os
7- from pathlib import Path
7+ from pathlib import Path , PurePath
88from tempfile import TemporaryDirectory
99
1010try :
@@ -253,12 +253,12 @@ def psconvert(self, **kwargs):
253253
254254 def savefig ( # noqa: PLR0912
255255 self ,
256- fname ,
257- transparent = False ,
258- crop = True ,
259- anti_alias = True ,
260- show = False ,
261- worldfile = False ,
256+ fname : str | PurePath ,
257+ transparent : bool = False ,
258+ crop : bool = True ,
259+ anti_alias : bool = True ,
260+ show : bool = False ,
261+ worldfile : bool = False ,
262262 ** kwargs ,
263263 ):
264264 """
@@ -280,45 +280,39 @@ def savefig( # noqa: PLR0912
280280 - EPS (``.eps``)
281281 - PDF (``.pdf``)
282282
283- Beside the above formats, you can also save the figure to a KML file
284- (``.kml``), with a companion PNG file generated automatically. The KML
285- file can be viewed in Google Earth.
283+ Besides the above formats, you can also save the figure to a KML file
284+ (``.kml``), with a companion PNG file generated automatically. The KML file can
285+ be viewed in Google Earth.
286286
287- You can pass in any keyword arguments that
288- :meth:`pygmt.Figure.psconvert` accepts.
287+ You can pass in any keyword arguments that :meth:`pygmt.Figure.psconvert`
288+ accepts.
289289
290290 Parameters
291291 ----------
292- fname : str
293- The desired figure file name, including the extension. See the list
294- of supported formats and their extensions above.
295- transparent : bool
296- If ``True``, will use a transparent background for the figure.
297- Only valid for PNG format.
298- crop : bool
299- If ``True``, will crop the figure canvas (page) to the plot area.
300- anti_alias: bool
301- If ``True``, will use anti-aliasing when creating raster images.
302- More specifically, it passes the arguments ``"t2"`` and ``"g2"``
303- to the ``anti_aliasing`` parameter of
304- :meth:`pygmt.Figure.psconvert`. Ignored if creating vector images.
305- show: bool
306- If ``True``, will open the figure in an external viewer.
307- worldfile : bool
308- If ``True``, will create a companion
309- `world file <https://en.wikipedia.org/wiki/World_file>`__ for the
310- figure. The world file will have the same name as the figure file
311- but with different extension (e.g. tfw for tif). See
312- https://en.wikipedia.org/wiki/World_file#Filename_extension
313- for the convention of world file extensions. This parameter only
314- works for raster image formats (except GeoTIFF).
315- dpi : int
316- Set raster resolution in dpi [Default is ``720`` for PDF, ``300``
317- for others].
292+ fname
293+ The desired figure file name, including the extension. See the list of
294+ supported formats and their extensions above.
295+ transparent
296+ Use a transparent background for the figure. Only valid for PNG format.
297+ crop
298+ Crop the figure canvas (page) to the plot area.
299+ anti_alias
300+ Use anti-aliasing when creating raster images. Ignored if creating vector
301+ images. More specifically, it passes the arguments ``"t2"`` and ``"g2"`` to
302+ the ``anti_aliasing`` parameter of :meth:`pygmt.Figure.psconvert`.
303+ show
304+ Display the figure in an external viewer.
305+ worldfile
306+ Create a companion `world file <https://en.wikipedia.org/wiki/World_file>`__
307+ for the figure. The world file will have the same name as the figure file
308+ but with different extension (e.g., ``.tfw`` for ``.tif``). See
309+ https://en.wikipedia.org/wiki/World_file#Filename_extension for the
310+ convention of world file extensions. This parameter only works for raster
311+ image formats (except GeoTIFF).
318312 **kwargs : dict
319- Additional keyword arguments passed to
320- :meth:`pygmt.Figure.psconvert`. Valid parameters are ``gs_path``,
321- ``gs_option``, ``resize``, `` bb_style``, and ``verbose``.
313+ Additional keyword arguments passed to :meth:`pygmt.Figure.psconvert`. Valid
314+ parameters are ``dpi``, `` gs_path``, ``gs_option``, ``resize ``,
315+ ``bb_style``, and ``verbose``.
322316 """
323317 # All supported formats
324318 fmts = {
@@ -382,7 +376,7 @@ def savefig( # noqa: PLR0912
382376 fname .with_suffix ("." + ext ).rename (fname )
383377
384378 if show :
385- launch_external_viewer (fname )
379+ launch_external_viewer (str ( fname ) )
386380
387381 def show (self , dpi = 300 , width = 500 , method = None , waiting = 0.5 , ** kwargs ):
388382 """
0 commit comments