2727
2828from matplotlib .axes import Axes , SubplotBase , subplot_class_factory
2929from matplotlib .blocking_input import BlockingMouseInput , BlockingKeyMouseInput
30- from matplotlib .gridspec import GridSpec , SubplotSpec
30+ from matplotlib .gridspec import GridSpec
3131import matplotlib .legend as mlegend
3232from matplotlib .patches import Rectangle
3333from matplotlib .text import Text
3434from matplotlib .transforms import (Affine2D , Bbox , BboxTransformTo ,
3535 TransformedBbox )
36- import matplotlib ._layoutbox as layoutbox
36+ import matplotlib ._layoutgrid as layoutgrid
3737
3838_log = logging .getLogger (__name__ )
3939
@@ -344,9 +344,9 @@ def __init__(self,
344344 subplotpars = SubplotParams ()
345345
346346 self .subplotpars = subplotpars
347+
347348 # constrained_layout:
348- self ._layoutbox = None
349- # set in set_constrained_layout_pads()
349+ self ._layoutgrid = None
350350 self .set_constrained_layout (constrained_layout )
351351
352352 self .set_tight_layout (tight_layout )
@@ -355,6 +355,13 @@ def __init__(self,
355355 self .clf ()
356356 self ._cachedRenderer = None
357357
358+ if self .get_constrained_layout ():
359+ # must be done *after* clf!
360+ self .init_layoutgrid ()
361+ # stub for subpanels:
362+ self .panels = []
363+ self .transPanel = self .transFigure
364+
358365 # groupers to keep track of x and y labels we want to align.
359366 # see self.align_xlabels and self.align_ylabels and
360367 # axis._get_tick_boxes_siblings
@@ -570,7 +577,7 @@ def get_constrained_layout_pads(self, relative=False):
570577 hspace = self ._constrained_layout_pads ['hspace' ]
571578
572579 if relative and (w_pad is not None or h_pad is not None ):
573- renderer0 = layoutbox .get_renderer (self )
580+ renderer0 = layoutgrid .get_renderer (self )
574581 dpi = renderer0 .dpi
575582 w_pad = w_pad * dpi / renderer0 .width
576583 h_pad = h_pad * dpi / renderer0 .height
@@ -729,22 +736,8 @@ def suptitle(self, t, **kwargs):
729736 sup .remove ()
730737 else :
731738 self ._suptitle = sup
732- self ._suptitle ._layoutbox = None
733- if self ._layoutbox is not None and not manual_position :
734- w_pad , h_pad , wspace , hspace = \
735- self .get_constrained_layout_pads (relative = True )
736- figlb = self ._layoutbox
737- self ._suptitle ._layoutbox = layoutbox .LayoutBox (
738- parent = figlb , artist = self ._suptitle ,
739- name = figlb .name + '.suptitle' )
740- # stack the suptitle on top of all the children.
741- # Some day this should be on top of all the children in the
742- # gridspec only.
743- for child in figlb .children :
744- if child is not self ._suptitle ._layoutbox :
745- layoutbox .vstack ([self ._suptitle ._layoutbox ,
746- child ],
747- padding = h_pad * 2. , strength = 'required' )
739+ if manual_position :
740+ self ._suptitle .set_in_layout (False )
748741 self .stale = True
749742 return self ._suptitle
750743
@@ -1405,6 +1398,7 @@ def add_subplot(self, *args, **kwargs):
14051398
14061399 def _add_axes_internal (self , key , ax ):
14071400 """Private helper for `add_axes` and `add_subplot`."""
1401+ #self._localaxes += [ax]
14081402 self ._axstack .add (key , ax )
14091403 self .sca (ax )
14101404 ax ._remove_method = self .delaxes
@@ -1570,6 +1564,7 @@ def _break_share_link(ax, grouper):
15701564 return None
15711565
15721566 self ._axstack .remove (ax )
1567+ # self._localaxes.remove(ax)
15731568 self ._axobservers .process ("_axes_change_event" , self )
15741569 self .stale = True
15751570
@@ -1609,7 +1604,7 @@ def clf(self, keep_observers=False):
16091604 self ._axobservers = cbook .CallbackRegistry ()
16101605 self ._suptitle = None
16111606 if self .get_constrained_layout ():
1612- layoutbox .nonetree (self ._layoutbox )
1607+ layoutgrid .nonetree (self ._layoutgrid )
16131608 self .stale = True
16141609
16151610 def clear (self , keep_observers = False ):
@@ -1919,12 +1914,9 @@ def __getstate__(self):
19191914 in _pylab_helpers .Gcf .figs .values ():
19201915 state ['_restore_to_pylab' ] = True
19211916
1922- # set all the layoutbox information to None. kiwisolver objects can't
1917+ # set all the layoutgrid information to None. kiwisolver objects can't
19231918 # be pickled, so we lose the layout options at this point.
1924- state .pop ('_layoutbox' , None )
1925- # suptitle:
1926- if self ._suptitle is not None :
1927- self ._suptitle ._layoutbox = None
1919+ state .pop ('_layoutgrid' , None )
19281920
19291921 return state
19301922
@@ -1941,7 +1933,7 @@ def __setstate__(self, state):
19411933
19421934 # re-initialise some of the unstored state information
19431935 FigureCanvasBase (self ) # Set self.canvas.
1944- self ._layoutbox = None
1936+ self ._layoutgrid = None
19451937
19461938 if restore_to_pylab :
19471939 # lazy import to avoid circularity
@@ -2323,24 +2315,22 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
23232315
23242316 return bbox_inches
23252317
2326- def init_layoutbox (self ):
2327- """Initialize the layoutbox for use in constrained_layout."""
2328- if self ._layoutbox is None :
2329- self ._layoutbox = layoutbox .LayoutBox (
2330- parent = None , name = 'figlb' , artist = self )
2331- self ._layoutbox .constrain_geometry (0. , 0. , 1. , 1. )
2318+ def init_layoutgrid (self ):
2319+ """Initialize the layoutgrid for use in constrained_layout."""
2320+ self ._layoutgrid = layoutgrid .LayoutGrid (
2321+ parent = None , name = 'figlb' )
23322322
23332323 def execute_constrained_layout (self , renderer = None ):
23342324 """
2335- Use ``layoutbox `` to determine pos positions within axes.
2325+ Use ``layoutgrid `` to determine pos positions within axes.
23362326
23372327 See also `.set_constrained_layout_pads`.
23382328 """
23392329
23402330 from matplotlib ._constrained_layout import do_constrained_layout
23412331
23422332 _log .debug ('Executing constrainedlayout' )
2343- if self ._layoutbox is None :
2333+ if self ._layoutgrid is None :
23442334 cbook ._warn_external ("Calling figure.constrained_layout, but "
23452335 "figure not setup to do constrained layout. "
23462336 " You either called GridSpec without the "
@@ -2355,7 +2345,7 @@ def execute_constrained_layout(self, renderer=None):
23552345 w_pad = w_pad / width
23562346 h_pad = h_pad / height
23572347 if renderer is None :
2358- renderer = layoutbox .get_renderer (fig )
2348+ renderer = layoutgrid .get_renderer (fig )
23592349 do_constrained_layout (fig , renderer , h_pad , w_pad , hspace , wspace )
23602350
23612351 @cbook ._delete_parameter ("3.2" , "renderer" )
0 commit comments