7474 %(units.em)s
7575"""
7676_tight_docstring = """
77- wequal, hequal, equal : bool, default: False
77+ wequal, hequal, equal : bool, default: :rc:`subplots.equalspace`
7878 Whether to make the tight layout algorithm apply equal spacing
7979 between columns, rows, or both.
80+ wgroup, hgroup, group : bool, default: :rc:`subplot.groupspace`
81+ Whether to make the tight layout algorithm just consider spaces between
82+ adjacent subplots instead of entire columns and rows of subplots.
8083outerpad : unit-spec, default: :rc:`subplots.outerpad`
8184 The scalar tight layout padding around the left, right, top, bottom figure edges.
8285 %(units.em)s
@@ -276,8 +279,10 @@ def __init__(self, nrows=1, ncols=1, **kwargs):
276279 self ._panelpad = units (panelpad , 'em' , 'in' )
277280 self ._hpad_total = [units (pad , 'em' , 'in' )] * (nrows - 1 )
278281 self ._wpad_total = [units (pad , 'em' , 'in' )] * (ncols - 1 )
279- self ._hequal = False
280- self ._wequal = False
282+ self ._hequal = rc ['subplots.equalspace' ]
283+ self ._wequal = rc ['subplots.equalspace' ]
284+ self ._hgroup = rc ['subplots.groupspace' ]
285+ self ._wgroup = rc ['subplots.groupspace' ]
281286 self ._hpanels = ['' ] * nrows # axes and figure panel identification
282287 self ._wpanels = ['' ] * ncols
283288 self ._fpanels = { # array representation of figure panel spans
@@ -691,11 +696,13 @@ def _get_tight_space(self, w):
691696 return
692697 if w == 'w' :
693698 x , y = 'xy'
699+ group = self ._wgroup
694700 nacross = self .nrows_total
695701 space = self .wspace_total
696702 pad = self .wpad_total
697703 else :
698704 x , y = 'yx'
705+ group = self ._hgroup
699706 nacross = self .ncols_total
700707 space = self .hspace_total
701708 pad = self .hpad_total
@@ -736,9 +743,14 @@ def _get_tight_space(self, w):
736743 break
737744 else :
738745 if axs1 and axs2 :
739- groups .append ([ set (axs1 ), set (axs2 )] ) # form new group
746+ groups .append (( set (axs1 ), set (axs2 )) ) # form new group
740747 # Determing the spaces using cached tight bounding boxes
741748 # NOTE: Set gridspec space to zero if there are no adjacent edges
749+ if not group :
750+ groups = [(
751+ set (ax for (group1 , _ ) in groups for ax in group1 ),
752+ set (ax for (_ , group2 ) in groups for ax in group2 ),
753+ )]
742754 margins = []
743755 for (group1 , group2 ) in groups :
744756 x1 = max (ax ._range_tightbbox (x )[1 ] for ax in group1 )
@@ -915,6 +927,7 @@ def _update_params(
915927 wspace = None , hspace = None , space = None ,
916928 wpad = None , hpad = None , pad = None ,
917929 wequal = None , hequal = None , equal = None ,
930+ wgroup = None , hgroup = None , group = None ,
918931 outerpad = None , innerpad = None , panelpad = None ,
919932 hratios = None , wratios = None , width_ratios = None , height_ratios = None ,
920933 ):
@@ -924,24 +937,29 @@ def _update_params(
924937 # Assign scalar args
925938 # WARNING: The key signature here is critical! Used in ui.py to
926939 # separate out figure keywords and gridspec keywords.
927- def _assign_scalar (key , value ):
940+ def _assign_scalar (key , value , convert = True ):
928941 if value is None :
929942 return
930943 if not np .isscalar (value ):
931944 raise ValueError (f'Unexpected { key } ={ value !r} . Must be scalar.' )
932- value = units (value , 'em' , 'in' )
945+ if convert :
946+ value = units (value , 'em' , 'in' )
933947 setattr (self , f'_{ key } ' , value )
934948 hequal = _not_none (hequal , equal )
935949 wequal = _not_none (wequal , equal )
950+ hgroup = _not_none (hgroup , group )
951+ wgroup = _not_none (wgroup , group )
936952 _assign_scalar ('left' , left )
937953 _assign_scalar ('right' , right )
938954 _assign_scalar ('bottom' , bottom )
939955 _assign_scalar ('top' , top )
940- _assign_scalar ('hequal' , hequal )
941- _assign_scalar ('wequal' , wequal )
942956 _assign_scalar ('panelpad' , panelpad )
943957 _assign_scalar ('outerpad' , outerpad )
944958 _assign_scalar ('innerpad' , innerpad )
959+ _assign_scalar ('hequal' , hequal , convert = False )
960+ _assign_scalar ('wequal' , wequal , convert = False )
961+ _assign_scalar ('hgroup' , hgroup , convert = False )
962+ _assign_scalar ('wgroup' , wgroup , convert = False )
945963
946964 # Assign vector args
947965 # NOTE: Here we employ obfuscation that skips 'panel' indices. So users could
0 commit comments