@@ -354,41 +354,38 @@ def savefig( # noqa: PLR0912
354
354
prefix , suffix = fname .with_suffix ("" ).as_posix (), fname .suffix
355
355
ext = suffix [1 :].lower () # Remove the . and normalize to lowercase
356
356
357
- if ext == "jpeg" : # Alias jpeg to jpg
358
- ext = "jpg"
359
- elif ext == "tiff" : # GeoTIFF
360
- kwargs ["W" ] = "+g"
361
- elif ext == "kml" : # KML
362
- kwargs ["W" ] = "+k"
363
-
364
- if ext not in fmts :
365
- if ext == "ps" :
366
- raise GMTInvalidInput (
367
- "Extension '.ps' is not supported. "
368
- "Please use '.eps' or '.pdf' instead."
369
- )
370
- raise GMTInvalidInput (f"Unknown extension '.{ ext } '." )
357
+ match ext :
358
+ case "jpeg" : # Alias jpeg to jpg
359
+ ext = "jpg"
360
+ case "tiff" : # GeoTIFF
361
+ kwargs ["W" ] = "+g"
362
+ case "kml" : # KML
363
+ kwargs ["W" ] = "+k"
364
+ case "ps" :
365
+ msg = "Extension '.ps' is not supported. Use '.eps' or '.pdf' instead."
366
+ raise GMTInvalidInput (msg )
367
+ case ext if ext not in fmts :
368
+ raise GMTInvalidInput (f"Unknown extension '.{ ext } '." )
369
+
371
370
fmt = fmts [ext ]
372
371
if transparent :
373
372
if fmt != "g" :
374
- raise GMTInvalidInput (
375
- f"Transparency unavailable for '{ ext } ', only for png."
376
- )
373
+ msg = f"Transparency unavailable for '{ ext } ', only for png."
374
+ raise GMTInvalidInput (msg )
377
375
fmt = fmt .upper ()
378
376
if anti_alias :
379
377
kwargs ["Qt" ] = 2
380
378
kwargs ["Qg" ] = 2
381
379
382
380
if worldfile :
383
381
if ext in {"eps" , "kml" , "pdf" , "tiff" }:
384
- raise GMTInvalidInput (
385
- f"Saving a world file is not supported for '{ ext } ' format."
386
- )
382
+ msg = f"Saving a world file is not supported for '{ ext } ' format."
383
+ raise GMTInvalidInput (msg )
387
384
kwargs ["W" ] = True
388
385
389
386
self .psconvert (prefix = prefix , fmt = fmt , crop = crop , ** kwargs )
390
387
391
- # Remove the .pgw world file if exists
388
+ # Remove the .pgw world file if exists.
392
389
# Not necessary after GMT 6.5.0.
393
390
# See upstream fix https://github.com/GenericMappingTools/gmt/pull/7865
394
391
if ext == "tiff" :
0 commit comments