@@ -100,6 +100,7 @@ class Figure:
100100 def __init__ (self ) -> None :
101101 self ._name = unique_name ()
102102 self ._preview_dir = TemporaryDirectory (prefix = f"{ self ._name } -preview-" )
103+ self ._current_region = None # Track the current region
103104 self ._activate_figure ()
104105
105106 def __del__ (self ) -> None :
@@ -124,11 +125,37 @@ def region(self) -> np.ndarray:
124125 """
125126 The geographic WESN bounding box for the current figure.
126127 """
128+ # First try to return the tracked current region
129+ if self ._current_region is not None :
130+ return self ._current_region
131+
132+ # Fall back to extracting region from GMT (for backward compatibility)
127133 self ._activate_figure ()
128134 with Session () as lib :
129135 wesn = lib .extract_region ()
130136 return wesn
131137
138+ def _update_current_region (self , region ) -> None :
139+ """
140+ Update the current region tracking.
141+
142+ Parameters
143+ ----------
144+ region : str, list, or np.ndarray
145+ The region to set as current.
146+ """
147+ if region is not None :
148+ # Convert region to numpy array for consistency
149+ if isinstance (region , str ):
150+ # For string regions like "g" or "JP", we can't convert to array
151+ # We'll set it to None and let GMT handle it
152+ self ._current_region = None
153+ else :
154+ # Convert list or array to numpy array
155+ self ._current_region = np .asarray (region )
156+ else :
157+ self ._current_region = None
158+
132159 def savefig (
133160 self ,
134161 fname : PathLike ,
0 commit comments