@@ -2084,9 +2084,13 @@ def tight_layout(self, renderer=None, pad=1.08, h_pad=None, w_pad=None,
2084
2084
pad = pad , h_pad = h_pad , w_pad = w_pad , rect = rect )
2085
2085
self .subplots_adjust (** kwargs )
2086
2086
2087
- def align_xlabels (self , axs = None , renderer = None ):
2087
+ def align_xlabels (self , axs = None ):
2088
2088
"""
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.
2090
2094
2091
2095
If a label is on the bottom, it is aligned with labels on axes that
2092
2096
also have their label on the bottom and that have the same
@@ -2096,11 +2100,8 @@ def align_xlabels(self, axs=None, renderer=None):
2096
2100
Parameters
2097
2101
----------
2098
2102
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.
2104
2105
2105
2106
See Also
2106
2107
--------
@@ -2121,11 +2122,6 @@ def align_xlabels(self, axs=None, renderer=None):
2121
2122
2122
2123
"""
2123
2124
2124
- from .tight_layout import get_renderer
2125
-
2126
- if renderer is None :
2127
- renderer = get_renderer (self )
2128
-
2129
2125
if axs is None :
2130
2126
axs = self .axes
2131
2127
@@ -2135,25 +2131,30 @@ def align_xlabels(self, axs=None, renderer=None):
2135
2131
_log .debug (' Working on: %s' , ax .get_xlabel ())
2136
2132
ss = ax .get_subplotspec ()
2137
2133
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`.
2140
2142
for axc in axs :
2141
2143
if axc .xaxis .get_label_position () == labpo :
2142
2144
ss = axc .get_subplotspec ()
2143
2145
nrows , ncols , rowc0 , rowc1 , colc , col1 = \
2144
2146
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 ]
2153
2150
2154
- def align_ylabels (self , axs = None , renderer = None ):
2151
+ def align_ylabels (self , axs = None ):
2155
2152
"""
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.
2157
2158
2158
2159
If a label is on the left, it is aligned with labels on axes that
2159
2160
also have their label on the left and that have the same
@@ -2163,11 +2164,8 @@ def align_ylabels(self, axs=None, renderer=None):
2163
2164
Parameters
2164
2165
----------
2165
2166
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.
2171
2169
2172
2170
See Also
2173
2171
--------
@@ -2187,11 +2185,6 @@ def align_ylabels(self, axs=None, renderer=None):
2187
2185
2188
2186
"""
2189
2187
2190
- from .tight_layout import get_renderer
2191
-
2192
- if renderer is None :
2193
- renderer = get_renderer (self )
2194
-
2195
2188
if axs is None :
2196
2189
axs = self .axes
2197
2190
@@ -2202,97 +2195,44 @@ def align_ylabels(self, axs=None, renderer=None):
2202
2195
nrows , ncols , row0 , row1 , col0 , col1 = ss .get_rows_columns ()
2203
2196
same = [ax ]
2204
2197
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`.
2205
2204
for axc in axs :
2206
2205
if axc != ax :
2207
2206
if axc .yaxis .get_label_position () == labpo :
2208
2207
ss = axc .get_subplotspec ()
2209
2208
nrows , ncols , row0 , row1 , colc0 , colc1 = \
2210
2209
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 ]
2272
2213
2273
- def align_labels (self , axs = None , renderer = None ):
2214
+ def align_labels (self , axs = None ):
2274
2215
"""
2275
2216
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.
2277
2221
2278
2222
Parameters
2279
2223
----------
2280
2224
axs : list of `~matplotlib.axes.Axes` (None)
2281
2225
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.
2286
2227
2287
2228
See Also
2288
2229
--------
2289
2230
matplotlib.figure.Figure.align_xlabels
2290
2231
2291
2232
matplotlib.figure.Figure.align_ylabels
2292
2233
"""
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 )
2296
2236
2297
2237
2298
2238
def figaspect (arg ):
0 commit comments