@@ -209,6 +209,33 @@ def get_renderer(fig):
209
209
return renderer
210
210
211
211
212
+ def get_subplotspec_list (axes_list ):
213
+ """
214
+ Return a list of subplotspec from the given list of axes. For an
215
+ instance of axes that does not support subplotspec, None is
216
+ inserted in the list.
217
+
218
+ """
219
+ subplotspec_list = []
220
+ 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 ()
226
+ else :
227
+ subplotspec = None
228
+
229
+ if subplotspec is not None and \
230
+ subplotspec .get_gridspec ().locally_modified_subplot_params ():
231
+
232
+ subplotspec = None
233
+
234
+ subplotspec_list .append (subplotspec )
235
+
236
+ return subplotspec_list
237
+
238
+
212
239
def get_tight_layout_figure (fig , axes_list , renderer ,
213
240
pad = 1.08 , h_pad = None , w_pad = None , rect = None ):
214
241
"""
@@ -244,21 +271,13 @@ def get_tight_layout_figure(fig, axes_list, renderer,
244
271
ncols_list = []
245
272
ax_bbox_list = []
246
273
247
- subplot_dict = {} # for axes_grid1, multiple axes can share
248
- # same subplot_interface. Thus we need to
249
- # join them together.
250
-
251
- for ax in axes_list :
252
- locator = ax .get_axes_locator ()
253
- if hasattr (locator , "get_subplotspec" ):
254
- subplotspec = locator .get_subplotspec ().get_topmost_subplotspec ()
255
- elif hasattr (ax , "get_subplotspec" ):
256
- subplotspec = ax .get_subplotspec ().get_topmost_subplotspec ()
257
- else :
258
- continue
274
+ subplot_dict = {} # multiple axes can share
275
+ # same subplot_interface (e.g, axes_grid1). Thus
276
+ # we need to join them together.
259
277
260
- if (subplotspec is None ) or \
261
- subplotspec .get_gridspec ().locally_modified_subplot_params ():
278
+ for ax , subplotspec in zip (axes_list ,
279
+ get_subplotspec_list (axes_list )):
280
+ if subplotspec is None :
262
281
continue
263
282
264
283
subplots = subplot_dict .setdefault (subplotspec , [])
0 commit comments