@@ -218,25 +218,24 @@ def get_subplotspec_list(axes_list):
218218 """
219219 subplotspec_list = []
220220 for ax in axes_list :
221- locator = ax .get_axes_locator ()
222- if hasattr (locator , "get_subplotspec" ):
223- subplotspec = locator .get_subplotspec ().get_topmost_subplotspec ()
224- elif hasattr (ax , "get_subplotspec" ):
225- subplotspec = ax .get_subplotspec ().get_topmost_subplotspec ()
221+ axes_or_locator = ax .get_axes_locator ()
222+ if axes_or_locator is None :
223+ axes_or_locator = ax
224+
225+ if hasattr (axes_or_locator , "get_subplotspec" ):
226+ subplotspec = axes_or_locator .get_subplotspec ()
227+ subplotspec = subplotspec .get_topmost_subplotspec ()
228+ if subplotspec .get_gridspec ().locally_modified_subplot_params ():
229+ subplotspec = None
226230 else :
227231 subplotspec = None
228232
229- if subplotspec is not None and \
230- subplotspec .get_gridspec ().locally_modified_subplot_params ():
231-
232- subplotspec = None
233-
234233 subplotspec_list .append (subplotspec )
235234
236235 return subplotspec_list
237236
238237
239- def get_tight_layout_figure (fig , axes_list , renderer ,
238+ def get_tight_layout_figure (fig , axes_list , subplotspec_list , renderer ,
240239 pad = 1.08 , h_pad = None , w_pad = None , rect = None ):
241240 """
242241 Return subplot parameters for tight-layouted-figure with specified
@@ -248,6 +247,9 @@ def get_tight_layout_figure(fig, axes_list, renderer,
248247
249248 *axes_list* : a list of axes
250249
250+ *subplotspec_list* : a list of subplotspec associated with each
251+ axes in axes_list
252+
251253 *renderer* : renderer instance
252254
253255 *pad* : float
@@ -265,7 +267,6 @@ def get_tight_layout_figure(fig, axes_list, renderer,
265267 """
266268
267269
268- subplotspec_list = []
269270 subplot_list = []
270271 nrows_list = []
271272 ncols_list = []
@@ -275,8 +276,10 @@ def get_tight_layout_figure(fig, axes_list, renderer,
275276 # same subplot_interface (e.g, axes_grid1). Thus
276277 # we need to join them together.
277278
279+ subplotspec_list2 = []
280+
278281 for ax , subplotspec in zip (axes_list ,
279- get_subplotspec_list ( axes_list ) ):
282+ subplotspec_list ):
280283 if subplotspec is None :
281284 continue
282285
@@ -286,7 +289,7 @@ def get_tight_layout_figure(fig, axes_list, renderer,
286289 myrows , mycols , _ , _ = subplotspec .get_geometry ()
287290 nrows_list .append (myrows )
288291 ncols_list .append (mycols )
289- subplotspec_list .append (subplotspec )
292+ subplotspec_list2 .append (subplotspec )
290293 subplot_list .append (subplots )
291294 ax_bbox_list .append (subplotspec .get_position (fig ))
292295
@@ -296,7 +299,7 @@ def get_tight_layout_figure(fig, axes_list, renderer,
296299 max_ncols = max (ncols_list )
297300
298301 num1num2_list = []
299- for subplotspec in subplotspec_list :
302+ for subplotspec in subplotspec_list2 :
300303 rows , cols , num1 , num2 = subplotspec .get_geometry ()
301304 div_row , mod_row = divmod (max_nrows , rows )
302305 div_col , mod_col = divmod (max_ncols , cols )
0 commit comments