@@ -539,14 +539,10 @@ def match_submerged_margins(layoutgrids, fig):
539539
540540 # interior columns:
541541 if len (ss1 .colspan ) > 1 :
542- maxsubl = np .max (
543- lg1 .margin_vals ['left' ][ss1 .colspan [1 :]] +
544- lg1 .margin_vals ['leftcb' ][ss1 .colspan [1 :]]
545- )
546- maxsubr = np .max (
547- lg1 .margin_vals ['right' ][ss1 .colspan [:- 1 ]] +
548- lg1 .margin_vals ['rightcb' ][ss1 .colspan [:- 1 ]]
549- )
542+ leftcb = lg1 .margin_vals ['leftcb' ][ss1 .colspan [1 :]]
543+ rightcb = lg1 .margin_vals ['rightcb' ][ss1 .colspan [:- 1 ]]
544+ maxsubl = np .max (lg1 .margin_vals ['left' ][ss1 .colspan [1 :]] + leftcb )
545+ maxsubr = np .max (lg1 .margin_vals ['right' ][ss1 .colspan [:- 1 ]] + rightcb )
550546 for ax2 in axs :
551547 ss2 = ax2 .get_subplotspec ()
552548 lg2 = layoutgrids [ss2 .get_gridspec ()]
@@ -561,22 +557,17 @@ def match_submerged_margins(layoutgrids, fig):
561557 lg2 .margin_vals ['rightcb' ][ss2 .colspan [:- 1 ]])
562558 if maxsubr2 > maxsubr :
563559 maxsubr = maxsubr2
564- for i in ss1 .colspan [1 :]:
565- lg1 .edit_margin_min ('left' , maxsubl , cell = i )
566- for i in ss1 .colspan [:- 1 ]:
567- lg1 .edit_margin_min ('right' , maxsubr , cell = i )
560+ for i , cb in zip ( ss1 .colspan [1 :], leftcb ) :
561+ lg1 .edit_margin_min ('left' , maxsubl - cb , cell = i )
562+ for i , cb in zip ( ss1 .colspan [:- 1 ], rightcb ) :
563+ lg1 .edit_margin_min ('right' , maxsubr - cb , cell = i )
568564
569565 # interior rows:
570566 if len (ss1 .rowspan ) > 1 :
571- maxsubt = np .max (
572- lg1 .margin_vals ['top' ][ss1 .rowspan [1 :]] +
573- lg1 .margin_vals ['topcb' ][ss1 .rowspan [1 :]]
574- )
575- maxsubb = np .max (
576- lg1 .margin_vals ['bottom' ][ss1 .rowspan [:- 1 ]] +
577- lg1 .margin_vals ['bottomcb' ][ss1 .rowspan [:- 1 ]]
578- )
579-
567+ topcb = lg1 .margin_vals ['topcb' ][ss1 .rowspan [1 :]]
568+ bottomcb = lg1 .margin_vals ['bottomcb' ][ss1 .rowspan [:- 1 ]]
569+ maxsubt = np .max (lg1 .margin_vals ['top' ][ss1 .rowspan [1 :]] + topcb )
570+ maxsubb = np .max (lg1 .margin_vals ['bottom' ][ss1 .rowspan [:- 1 ]] + bottomcb )
580571 for ax2 in axs :
581572 ss2 = ax2 .get_subplotspec ()
582573 lg2 = layoutgrids [ss2 .get_gridspec ()]
@@ -590,10 +581,10 @@ def match_submerged_margins(layoutgrids, fig):
590581 lg2 .margin_vals ['bottom' ][ss2 .rowspan [:- 1 ]] +
591582 lg2 .margin_vals ['bottomcb' ][ss2 .rowspan [:- 1 ]]
592583 ), maxsubb ])
593- for i in ss1 .rowspan [1 :]:
594- lg1 .edit_margin_min ('top' , maxsubt , cell = i )
595- for i in ss1 .rowspan [:- 1 ]:
596- lg1 .edit_margin_min ('bottom' , maxsubb , cell = i )
584+ for i , cb in zip ( ss1 .rowspan [1 :], topcb ) :
585+ lg1 .edit_margin_min ('top' , maxsubt - cb , cell = i )
586+ for i , cb in zip ( ss1 .rowspan [:- 1 ], bottomcb ) :
587+ lg1 .edit_margin_min ('bottom' , maxsubb - cb , cell = i )
597588
598589 return axs
599590
0 commit comments