@@ -258,55 +258,53 @@ def right_most_spaces(self) -> list[right_spaces]:
258258 @property
259259 def panel_width (self ) -> float :
260260 """
261- A representative width for panels of the nodes
261+ A width of all panels in this composition
262262 """
263263 return sum (self .panel_widths )
264264
265265 @property
266266 def panel_height (self ) -> float :
267267 """
268- A representative height for panels of the nodes
268+ A height of all panels in this composition
269269 """
270270 return sum (self .panel_heights )
271271
272272 @property
273273 def plot_width (self ) -> float :
274274 """
275- A representative for width for plots of the nodes
275+ A width of all plots in this tree/composition
276276 """
277- return sum ( self .plot_widths )
277+ return self .gridspec . width
278278
279279 @property
280280 def plot_height (self ) -> float :
281281 """
282- A representative for height for plots of the nodes
282+ A height of all plots in this tree/composition
283283 """
284- return sum ( self .plot_heights )
284+ return self .gridspec . height
285285
286286 @property
287287 def panel_widths (self ) -> Sequence [float ]:
288288 """
289289 Widths [figure space] of the panels along horizontal dimension
290-
291- For each column, the effective panel width is the width of the
292- shortest panel.
293290 """
294- n = self .ncol
291+ # This method is used after aligning the panels. Therefore, the
292+ # wides panel_width (i.e. max()) is the good representative width
293+ # of the column.
294+ w = self .plot_width / self .ncol
295295 return [
296- max ([ node .panel_width if node else 1 / n for node in col ])
296+ max (node .panel_width for node in col if node ) if any ( col ) else w
297297 for col in self .grid .iter_cols ()
298298 ]
299299
300300 @property
301301 def panel_heights (self ) -> Sequence [float ]:
302302 """
303303 Heights [figure space] of the panels along vertical dimension
304-
305- For each row, the representative height is that of the shortest panel.
306304 """
307- n = self .nrow
305+ h = self . plot_height / self .nrow
308306 return [
309- max ([node .panel_height if node else 1 / n for node in row ])
307+ max ([node .panel_height for node in row if node ]) if any ( row ) else h
310308 for row in self .grid .iter_rows ()
311309 ]
312310
@@ -315,11 +313,11 @@ def plot_widths(self) -> Sequence[float]:
315313 """
316314 Widths [figure space] of the plots along horizontal dimension
317315
318- For each column, the representative width is that of the shortest plot.
316+ For each column, the representative width is that of the widest plot.
319317 """
320- n = self .ncol
318+ w = self . gridspec . width / self .ncol
321319 return [
322- max ([node .plot_width if node else 1 / n for node in col ])
320+ max ([node .plot_width if node else w for node in col ])
323321 for col in self .grid .iter_cols ()
324322 ]
325323
@@ -328,14 +326,32 @@ def plot_heights(self) -> Sequence[float]:
328326 """
329327 Heights [figure space] of the plots along vertical dimension
330328
331- For each row, the representative height is that of the shortest plot.
329+ For each row, the representative height is that of the tallest plot.
332330 """
333- n = self .nrow
331+ h = self . gridspec . height / self .nrow
334332 return [
335- max ([node .plot_height if node else 1 / n for node in row ])
333+ max ([node .plot_height if node else h for node in row ])
336334 for row in self .grid .iter_rows ()
337335 ]
338336
337+ @property
338+ def panel_width_ratios (self ) -> Sequence [float ]:
339+ """
340+ The relative widths of the panels in the composition
341+
342+ These are normalised to have a mean = 1.
343+ """
344+ return cast ("Sequence[float]" , self .cmp ._layout .widths )
345+
346+ @property
347+ def panel_height_ratios (self ) -> Sequence [float ]:
348+ """
349+ The relative heights of the panels in the composition
350+
351+ These are normalised to have a mean = 1.
352+ """
353+ return cast ("Sequence[float]" , self .cmp ._layout .heights )
354+
339355 def bottom_spaces_in_row (self , r : int ) -> list [bottom_spaces ]:
340356 spaces : list [bottom_spaces ] = []
341357 for node in self .grid [r , :]:
@@ -509,21 +525,22 @@ def align_axis_titles(self):
509525 tree .align_axis_titles ()
510526
511527 def resize_widths (self ):
512- n = self .ncol
513- resize_ratios = np .array (self .cmp ._layout .widths )
514- base_panel_widths = np .ones (n ) * self .panel_width
515- scaled_panel_widths = base_panel_widths * resize_ratios
528+ # The scaling calcuation to get the new panel width is
529+ # straight-forward because the ratios have a mean of 1.
530+ # So the multiplication preserves the total panel width.
531+ new_panel_widths = np .mean (self .panel_widths ) * np .array (
532+ self .panel_width_ratios
533+ )
516534 non_panel_space = np .array (self .plot_widths ) - self .panel_widths
517- new_plot_widths = scaled_panel_widths + non_panel_space
535+ new_plot_widths = new_panel_widths + non_panel_space
518536 width_ratios = new_plot_widths / new_plot_widths .max ()
519537 self .gridspec .set_width_ratios (width_ratios )
520538
521539 def resize_heights (self ):
522- n = self .nrow
523- resize_ratios = np .array (self .cmp ._layout .heights )
524- base_panel_heights = np .ones (n ) * self .panel_height
525- scaled_panel_heights = base_panel_heights * resize_ratios
540+ new_panel_heights = np .mean (self .panel_heights ) * np .array (
541+ self .panel_height_ratios
542+ )
526543 non_panel_space = np .array (self .plot_heights ) - self .panel_heights
527- new_plot_heights = scaled_panel_heights + non_panel_space
544+ new_plot_heights = new_panel_heights + non_panel_space
528545 height_ratios = new_plot_heights / new_plot_heights .max ()
529546 self .gridspec .set_height_ratios (height_ratios )
0 commit comments