@@ -47,11 +47,11 @@ def plot_array(
4747 title : str = "" ,
4848 xlabel : str = "" ,
4949 ylabel : str = "" ,
50- colormap : str = "jet" ,
50+ colormap : Optional [ str ] = None ,
5151 vmin : Optional [float ] = None ,
5252 vmax : Optional [float ] = None ,
5353 use_log10 : bool = False ,
54- aspect : str = "auto" ,
54+ cb_unit : Optional [ str ] = None ,
5555 origin_imshow : str = "upper" ,
5656 # --- figure control (used only when ax is None) -----------------------------
5757 figsize : Optional [Tuple [int , int ]] = None ,
@@ -105,8 +105,6 @@ def plot_array(
105105 Explicit color scale limits.
106106 use_log10
107107 When ``True`` a ``LogNorm`` is applied.
108- aspect
109- Passed directly to ``imshow``.
110108 origin_imshow
111109 Passed directly to ``imshow`` (``"upper"`` or ``"lower"``).
112110 figsize
@@ -135,6 +133,10 @@ def plot_array(
135133 if array is None or array .size == 0 :
136134 return
137135
136+ if colormap is None :
137+ from autoarray .plot .utils import _default_colormap
138+ colormap = _default_colormap ()
139+
138140 # convert overlay params (safe for None and already-numpy inputs)
139141 border = numpy_grid (border )
140142 origin = numpy_grid (origin )
@@ -180,16 +182,33 @@ def plot_array(
180182 else :
181183 norm = None
182184
185+ # Compute the axes-box aspect ratio from the data extent so that the
186+ # physical cell is correctly shaped and tight_layout has no whitespace
187+ # to absorb. This reproduces the old "square" subplot behaviour where
188+ # ratio = x_range / y_range was passed to plt.subplot(aspect=ratio).
189+ if extent is not None :
190+ x_range = abs (extent [1 ] - extent [0 ])
191+ y_range = abs (extent [3 ] - extent [2 ])
192+ _box_aspect = (x_range / y_range ) if y_range > 0 else 1.0
193+ else :
194+ h , w = array .shape [:2 ]
195+ _box_aspect = (w / h ) if h > 0 else 1.0
196+
183197 im = ax .imshow (
184198 array ,
185199 cmap = colormap ,
186200 norm = norm ,
187201 extent = extent ,
188- aspect = aspect ,
202+ aspect = "auto" , # image fills the axes box; box shape set below
189203 origin = origin_imshow ,
190204 )
191205
192- plt .colorbar (im , ax = ax )
206+ # Shape the axes box to match the data so there is no surrounding
207+ # whitespace when the panel is embedded in a subplot grid.
208+ ax .set_aspect (_box_aspect , adjustable = "box" )
209+
210+ from autoarray .plot .utils import _apply_colorbar
211+ _apply_colorbar (im , ax , cb_unit = cb_unit , is_subplot = not owns_figure )
193212
194213 # --- overlays --------------------------------------------------------------
195214 if array_overlay is not None :
@@ -198,7 +217,7 @@ def plot_array(
198217 cmap = "Greys" ,
199218 alpha = 0.5 ,
200219 extent = extent ,
201- aspect = aspect ,
220+ aspect = "auto" ,
202221 origin = origin_imshow ,
203222 )
204223
@@ -223,7 +242,7 @@ def plot_array(
223242 ax .scatter (mesh_grid [:, 1 ], mesh_grid [:, 0 ], s = 1 , c = "w" , alpha = 0.5 )
224243
225244 if positions is not None :
226- colors = ["r " , "g" , "b" , "m" , "c" , "y" ]
245+ colors = ["k " , "g" , "b" , "m" , "c" , "y" ]
227246 for i , pos in enumerate (positions ):
228247 ax .scatter (pos [:, 1 ], pos [:, 0 ], s = 20 , c = colors [i % len (colors )], zorder = 5 )
229248
@@ -263,7 +282,7 @@ def plot_array(
263282 pass
264283
265284 # --- labels / ticks --------------------------------------------------------
266- apply_labels (ax , title = title , xlabel = xlabel , ylabel = ylabel )
285+ apply_labels (ax , title = title , xlabel = xlabel , ylabel = ylabel , is_subplot = not owns_figure )
267286
268287 if extent is not None :
269288 apply_extent (ax , extent )
0 commit comments