@@ -135,7 +135,7 @@ def region(self) -> np.ndarray:
135
135
wesn = lib .extract_region ()
136
136
return wesn
137
137
138
- def savefig ( # noqa: PLR0912
138
+ def savefig (
139
139
self ,
140
140
fname : str | PurePath ,
141
141
transparent : bool = False ,
@@ -177,7 +177,8 @@ def savefig( # noqa: PLR0912
177
177
The desired figure file name, including the extension. See the list of
178
178
supported formats and their extensions above.
179
179
transparent
180
- Use a transparent background for the figure. Only valid for PNG format.
180
+ Use a transparent background for the figure. Only valid for PNG format and
181
+ the PNG file asscoiated with KML format.
181
182
crop
182
183
Crop the figure canvas (page) to the plot area.
183
184
anti_alias
@@ -203,9 +204,9 @@ def savefig( # noqa: PLR0912
203
204
"bmp" : "b" ,
204
205
"eps" : "e" ,
205
206
"jpg" : "j" ,
206
- "kml" : "g" ,
207
+ "kml" : "G" if transparent is True else " g" ,
207
208
"pdf" : "f" ,
208
- "png" : "g" ,
209
+ "png" : "G" if transparent is True else " g" ,
209
210
"ppm" : "m" ,
210
211
"tif" : "t" ,
211
212
"tiff" : None , # GeoTIFF doesn't need the -T option
@@ -226,14 +227,12 @@ def savefig( # noqa: PLR0912
226
227
msg = "Extension '.ps' is not supported. Use '.eps' or '.pdf' instead."
227
228
raise GMTInvalidInput (msg )
228
229
case ext if ext not in fmts :
229
- raise GMTInvalidInput (f"Unknown extension '.{ ext } '." )
230
-
231
- fmt = fmts [ext ]
232
- if transparent :
233
- if fmt != "g" :
234
- msg = f"Transparency unavailable for '{ ext } ', only for png."
230
+ msg = f"Unknown extension '.{ ext } '."
235
231
raise GMTInvalidInput (msg )
236
- fmt = fmt .upper ()
232
+
233
+ if transparent and ext not in {"kml" , "png" }:
234
+ msg = f"Transparency unavailable for '{ ext } ', only for png and kml."
235
+ raise GMTInvalidInput (msg )
237
236
if anti_alias :
238
237
kwargs ["Qt" ] = 2
239
238
kwargs ["Qg" ] = 2
@@ -244,18 +243,17 @@ def savefig( # noqa: PLR0912
244
243
raise GMTInvalidInput (msg )
245
244
kwargs ["W" ] = True
246
245
247
- # pytest-mpl v0.17.0 added the "metadata" parameter to Figure.savefig, which
248
- # is not recognized. So remove it before calling Figure.psconvert.
246
+ # pytest-mpl v0.17.0 added the "metadata" parameter to Figure.savefig, which is
247
+ # not recognized. So remove it before calling Figure.psconvert.
249
248
kwargs .pop ("metadata" , None )
250
- self .psconvert (prefix = prefix , fmt = fmt , crop = crop , ** kwargs )
249
+ self .psconvert (prefix = prefix , fmt = fmts [ ext ] , crop = crop , ** kwargs )
251
250
252
- # Remove the .pgw world file if exists.
253
- # Not necessary after GMT 6.5.0.
251
+ # Remove the .pgw world file if exists. Not necessary after GMT 6.5.0.
254
252
# See upstream fix https://github.com/GenericMappingTools/gmt/pull/7865
255
253
if ext == "tiff" :
256
254
fname .with_suffix (".pgw" ).unlink (missing_ok = True )
257
255
258
- # Rename if file extension doesn't match the input file suffix
256
+ # Rename if file extension doesn't match the input file suffix.
259
257
if ext != suffix [1 :]:
260
258
fname .with_suffix ("." + ext ).rename (fname )
261
259
0 commit comments