@@ -114,6 +114,8 @@ def __init__(self, nrows=1, ncols=1, figsize=(640, 480),
114114 self ._axes_map : dict = {}
115115 self ._plots_map : dict = {}
116116 self ._insets_map : dict = {}
117+ self ._hspace : float | None = None
118+ self ._wspace : float | None = None
117119 with self .hold_trait_notifications ():
118120 self .fig_width = figsize [0 ]
119121 self .fig_height = figsize [1 ]
@@ -149,6 +151,29 @@ def set_help(self, text: str) -> None:
149151 """
150152 self .help_text = self ._resolve_help (text )
151153
154+ def subplots_adjust (self , hspace : float | None = None ,
155+ wspace : float | None = None ) -> None :
156+ """Set the spacing between subplot panels.
157+
158+ Only the arguments that are explicitly provided are updated; omitting
159+ an argument leaves the current value unchanged.
160+
161+ Parameters
162+ ----------
163+ hspace : float, optional
164+ Fraction of the average row height to use as vertical gap between
165+ panels. ``0.1`` adds a gap of 10 % of the mean row height.
166+ ``None`` (default) leaves the current hspace unchanged.
167+ wspace : float, optional
168+ Fraction of the average column width to use as horizontal gap.
169+ ``None`` (default) leaves the current wspace unchanged.
170+ """
171+ if hspace is not None :
172+ self ._hspace = float (hspace )
173+ if wspace is not None :
174+ self ._wspace = float (wspace )
175+ self ._push_layout ()
176+
152177 # ── subplot creation ──────────────────────────────────────────────────────
153178 def add_subplot (self , spec ) -> Axes :
154179 """Add a subplot cell and return its :class:`Axes`.
@@ -303,6 +328,8 @@ def _mg(flag, key):
303328 "panel_specs" : panel_specs ,
304329 "share_groups" : share_groups ,
305330 "inset_specs" : inset_specs ,
331+ "hspace" : self ._hspace ,
332+ "wspace" : self ._wspace ,
306333 })
307334
308335 # ── inset creation ────────────────────────────────────────────────────────
@@ -464,6 +491,25 @@ def _repr_html_(self) -> str:
464491 """
465492 return repr_html_iframe (self )
466493
494+ def close (self ) -> None :
495+ """Close the figure.
496+
497+ Fires a ``"close"`` event on every panel's :attr:`callbacks`, then
498+ hides the widget by setting its CSS ``display`` to ``"none"``.
499+ Subsequent calls are no-ops.
500+ """
501+ if getattr (self , "_closed" , False ):
502+ return
503+ self ._closed = True
504+ close_event = Event (event_type = "close" )
505+ for plot in self ._plots_map .values ():
506+ if hasattr (plot , "callbacks" ):
507+ plot .callbacks .fire (close_event )
508+ try :
509+ self .layout .display = "none"
510+ except Exception :
511+ pass
512+
467513 def __repr__ (self ) -> str :
468514 return (f"Figure({ self ._nrows } x{ self ._ncols } , "
469515 f"panels={ len (self ._plots_map )} , "
0 commit comments