@@ -569,22 +569,20 @@ def _repr_html_(self):
569569 )
570570
571571
572- def set_display (method = None ):
572+ def set_display (method : Literal [ "external" , "notebook" , "none" , None ] = None ):
573573 """
574574 Set the display method when calling :meth:`pygmt.Figure.show`.
575575
576576 Parameters
577577 ----------
578- method : str or None
578+ method
579579 The method to display an image preview. Choose from:
580580
581581 - ``"external"``: External PDF preview using the default PDF viewer
582582 - ``"notebook"``: Inline PNG preview in the current notebook
583583 - ``"none"``: Disable image preview
584- - ``None``: Reset to the default display method
585-
586- The default display method is ``"external"`` in Python consoles or
587- ``"notebook"`` in Jupyter notebooks.
584+ - ``None``: Reset to the default display method, which is either ``"external"``
585+ in Python consoles or ``"notebook"`` in Jupyter notebooks.
588586
589587 Examples
590588 --------
@@ -607,10 +605,13 @@ def set_display(method=None):
607605 >>> pygmt.set_display(method=None)
608606 >>> fig.show() # again, will show a PNG image in the current notebook
609607 """
610- if method in {"notebook" , "external" , "none" }:
611- SHOW_CONFIG ["method" ] = method
612- elif method is not None :
613- raise GMTInvalidInput (
614- f"Invalid display mode '{ method } ', "
615- "should be either 'notebook', 'external', 'none' or None."
616- )
608+ match method :
609+ case "external" | "notebook" | "none" :
610+ SHOW_CONFIG ["method" ] = method # type: ignore[assignment]
611+ case None :
612+ SHOW_CONFIG ["method" ] = _get_default_display_method () # type: ignore[assignment]
613+ case _:
614+ raise GMTInvalidInput (
615+ f"Invalid display method '{ method } '. Valid values are 'external',"
616+ "'notebook', 'none' or None."
617+ )
0 commit comments