@@ -2084,9 +2084,13 @@ def tight_layout(self, renderer=None, pad=1.08, h_pad=None, w_pad=None,
20842084 pad = pad , h_pad = h_pad , w_pad = w_pad , rect = rect )
20852085 self .subplots_adjust (** kwargs )
20862086
2087- def align_xlabels (self , axs = None , renderer = None ):
2087+ def align_xlabels (self , axs = None ):
20882088 """
2089- Align the xlabels of subplots in this figure.
2089+ Align the ylabels of subplots in the same subplot column if label
2090+ alignment is being done automatically (i.e. the label position is
2091+ not manually set).
2092+
2093+ Alignment persists for draw events after this is called.
20902094
20912095 If a label is on the bottom, it is aligned with labels on axes that
20922096 also have their label on the bottom and that have the same
@@ -2096,11 +2100,8 @@ def align_xlabels(self, axs=None, renderer=None):
20962100 Parameters
20972101 ----------
20982102 axs : list of `~matplotlib.axes.Axes` (None)
2099- Optional list of `~matplotlib.axes.Axes` to align
2100- the xlabels.
2101-
2102- renderer : (None)
2103- Optional renderer to do the adjustment on.
2103+ Optional list of (or ndarray) `~matplotlib.axes.Axes` to align
2104+ the xlabels. Default is to align all axes on the figure.
21042105
21052106 See Also
21062107 --------
@@ -2121,11 +2122,6 @@ def align_xlabels(self, axs=None, renderer=None):
21212122
21222123 """
21232124
2124- from .tight_layout import get_renderer
2125-
2126- if renderer is None :
2127- renderer = get_renderer (self )
2128-
21292125 if axs is None :
21302126 axs = self .axes
21312127
@@ -2135,25 +2131,30 @@ def align_xlabels(self, axs=None, renderer=None):
21352131 _log .debug (' Working on: %s' , ax .get_xlabel ())
21362132 ss = ax .get_subplotspec ()
21372133 nrows , ncols , row0 , row1 , col0 , col1 = ss .get_rows_columns ()
2138- same = [ax ]
2139- labpo = ax .xaxis .get_label_position ()
2134+ labpo = ax .xaxis .get_label_position () # top or bottom
2135+
2136+ # loop through other axes, and search for label positions
2137+ # that are same as this one, and that share the appropriate
2138+ # row number.
2139+ # Add to a list associated with each axes of sibblings.
2140+ # This list is inspected in `axis.draw` by
2141+ # `axis._update_label_position`.
21402142 for axc in axs :
21412143 if axc .xaxis .get_label_position () == labpo :
21422144 ss = axc .get_subplotspec ()
21432145 nrows , ncols , rowc0 , rowc1 , colc , col1 = \
21442146 ss .get_rows_columns ()
2145- if (labpo == 'bottom' ) and (rowc1 == row1 ):
2146- same += [axc ]
2147- elif (labpo == 'top' ) and (rowc0 == row0 ):
2148- same += [axc ]
2149-
2150- for axx in same :
2151- _log .debug (' Same: %s' , axx .xaxis .label )
2152- axx .xaxis ._align_label_siblings += [ax .xaxis ]
2147+ if (labpo == 'bottom' and rowc1 == row1 or
2148+ labpo == 'top' and rowc0 == row0 ):
2149+ axc .xaxis ._align_label_siblings += [ax .xaxis ]
21532150
2154- def align_ylabels (self , axs = None , renderer = None ):
2151+ def align_ylabels (self , axs = None ):
21552152 """
2156- Align the ylabels of subplots in this figure.
2153+ Align the ylabels of subplots in the same subplot column if label
2154+ alignment is being done automatically (i.e. the label position is
2155+ not manually set).
2156+
2157+ Alignment persists for draw events after this is called.
21572158
21582159 If a label is on the left, it is aligned with labels on axes that
21592160 also have their label on the left and that have the same
@@ -2163,11 +2164,8 @@ def align_ylabels(self, axs=None, renderer=None):
21632164 Parameters
21642165 ----------
21652166 axs : list of `~matplotlib.axes.Axes` (None)
2166- Optional list of `~matplotlib.axes.Axes` to align
2167- the ylabels.
2168-
2169- renderer : (None)
2170- Optional renderer to do the adjustment on.
2167+ Optional list (or ndarray) of `~matplotlib.axes.Axes` to align
2168+ the ylabels. Default is to align all axes on the figure.
21712169
21722170 See Also
21732171 --------
@@ -2187,11 +2185,6 @@ def align_ylabels(self, axs=None, renderer=None):
21872185
21882186 """
21892187
2190- from .tight_layout import get_renderer
2191-
2192- if renderer is None :
2193- renderer = get_renderer (self )
2194-
21952188 if axs is None :
21962189 axs = self .axes
21972190
@@ -2202,97 +2195,44 @@ def align_ylabels(self, axs=None, renderer=None):
22022195 nrows , ncols , row0 , row1 , col0 , col1 = ss .get_rows_columns ()
22032196 same = [ax ]
22042197 labpo = ax .yaxis .get_label_position ()
2198+ # loop through other axes, and search for label positions
2199+ # that are same as this one, and that share the appropriate
2200+ # column number.
2201+ # Add to a list associated with each axes of sibblings.
2202+ # This list is inspected in `axis.draw` by
2203+ # `axis._update_label_position`.
22052204 for axc in axs :
22062205 if axc != ax :
22072206 if axc .yaxis .get_label_position () == labpo :
22082207 ss = axc .get_subplotspec ()
22092208 nrows , ncols , row0 , row1 , colc0 , colc1 = \
22102209 ss .get_rows_columns ()
2211- if (labpo == 'left' ) and (colc0 == col0 ):
2212- same += [axc ]
2213- elif (labpo == 'right' ) and (colc1 == col1 ):
2214- same += [axc ]
2215- for axx in same :
2216- _log .debug (' Same: %s' , axx .yaxis .label )
2217- axx .yaxis ._align_label_siblings += [ax .yaxis ]
2218-
2219- # place holder until #9498 is merged...
2220- def align_titles (self , axs = None , renderer = None ):
2221- """
2222- Align the titles of subplots in this figure.
2223-
2224- Parameters
2225- ----------
2226- axs : list of `~matplotlib.axes.Axes` (None)
2227- Optional list of axes to align the xlabels.
2228-
2229- renderer : (None)
2230- Optional renderer to do the adjustment on.
2231-
2232- See Also
2233- --------
2234- matplotlib.figure.Figure.align_xlabels
2235-
2236- matplotlib.figure.Figure.align_ylabels
2237- """
2238-
2239- from .tight_layout import get_renderer
2240-
2241- if renderer is None :
2242- renderer = get_renderer (self )
2243-
2244- if axs is None :
2245- axs = self .axes
2246-
2247- while len (axs ):
2248- ax = axs .pop ()
2249- ax ._update_title_position (renderer )
2250- same = [ax ]
2251- if ax ._autolabelpos :
2252- ss = ax .get_subplotspec ()
2253- nrows , ncols , row0 , row1 , col0 , col1 = ss .get_rows_columns ()
2254- labpo = ax .xaxis .get_label_position ()
2255- for axc in axs :
2256- axc ._update_title_position (renderer )
2257- if axc ._autolabelpos :
2258- ss = axc .get_subplotspec ()
2259- nrows , ncols , rowc0 , rowc1 , colc , col1 = \
2260- ss .get_rows_columns ()
2261- if (rowc0 == row0 ):
2262- same += [axc ]
2263-
2264- x0 , y0 = ax .title .get_position ()
2265- for axx in same :
2266- x , y = axx .title .get_position ()
2267- if y > y0 :
2268- ax .title .set_position (x0 , y )
2269- y0 = y
2270- elif y0 > y :
2271- axx .title .set_positions (x , y0 )
2210+ if (labpo == 'left' and colc0 == col0 or
2211+ labpo == 'right' and colc1 == col1 ):
2212+ axc .yaxis ._align_label_siblings += [ax .yaxis ]
22722213
2273- def align_labels (self , axs = None , renderer = None ):
2214+ def align_labels (self , axs = None ):
22742215 """
22752216 Align the xlabels and ylabels of subplots with the same subplots
2276- row or column (respectively).
2217+ row or column (respectively) if label alignment is being
2218+ done automatically (i.e. the label position is not manually set).
2219+
2220+ Alignment persists for draw events after this is called.
22772221
22782222 Parameters
22792223 ----------
22802224 axs : list of `~matplotlib.axes.Axes` (None)
22812225 Optional list (or ndarray) of `~matplotlib.axes.Axes` to
2282- align the labels.
2283-
2284- renderer : (None)
2285- Optional renderer to do the adjustment on.
2226+ align the labels. Default is to align all axes on the figure.
22862227
22872228 See Also
22882229 --------
22892230 matplotlib.figure.Figure.align_xlabels
22902231
22912232 matplotlib.figure.Figure.align_ylabels
22922233 """
2293- self .align_xlabels (axs = axs , renderer = renderer )
2294- self .align_ylabels (axs = axs , renderer = renderer )
2295- # self.align_titles(axs=axs, renderer=renderer)
2234+ self .align_xlabels (axs = axs )
2235+ self .align_ylabels (axs = axs )
22962236
22972237
22982238def figaspect (arg ):
0 commit comments