@@ -279,18 +279,41 @@ def _make_margin_suptitles(fig, renderer, *, w_pad=0, h_pad=0):
279279 for panel in fig .subfigs :
280280 _make_margin_suptitles (panel , renderer , w_pad = w_pad , h_pad = h_pad )
281281
282- if fig ._suptitle is not None and fig ._suptitle .get_in_layout ():
283- invTransFig = fig .transSubfigure .inverted ().transform_bbox
282+ invTransFig = fig .transSubfigure .inverted ().transform_bbox
283+ if hasattr (fig , '_parent' ):
284+ parenttrans = fig ._parent .transSubfigure
285+ else :
284286 parenttrans = fig .transFigure
285- w_pad , h_pad = (fig .transSubfigure -
286- parenttrans ).transform ((w_pad , 1 - h_pad ))
287- w_pad , one = (fig .transSubfigure -
288- parenttrans ).transform ((w_pad , 1 ))
287+
288+ if fig ._suptitle is not None and fig ._suptitle .get_in_layout ():
289+ _ , h_pad = (fig .transSubfigure -
290+ parenttrans ).transform ((1.0 , 1.0 - h_pad ))
291+ _ , one = (fig .transSubfigure -
292+ parenttrans ).transform ((1.0 , 1 ))
289293 h_pad = one - h_pad
290294 bbox = invTransFig (fig ._suptitle .get_tightbbox (renderer ))
291295 p = fig ._suptitle .get_position ()
292- fig ._suptitle .set_position ((p [0 ], 1 - h_pad ))
293- fig ._layoutgrid .edit_margin_min ('top' , bbox .height + 2 * h_pad )
296+ fig ._suptitle .set_position ((p [0 ], 1.0 - h_pad ))
297+ fig ._layoutgrid .edit_margin_min ('top' , bbox .height + 2.0 * h_pad )
298+
299+ if fig ._supxlabel is not None and fig ._supxlabel .get_in_layout ():
300+ _ , h_pad = (fig .transSubfigure -
301+ parenttrans ).transform ((1.0 , h_pad ))
302+
303+ bbox = invTransFig (fig ._supxlabel .get_tightbbox (renderer ))
304+ p = fig ._supxlabel .get_position ()
305+ fig ._supxlabel .set_position ((p [0 ], h_pad ))
306+ fig ._layoutgrid .edit_margin_min ('bottom' , bbox .height + 2 * h_pad )
307+
308+
309+ if fig ._supylabel is not None and fig ._supxlabel .get_in_layout ():
310+ w_pad , _ = (fig .transSubfigure -
311+ parenttrans ).transform ((w_pad , 1.0 ))
312+
313+ bbox = invTransFig (fig ._supylabel .get_tightbbox (renderer ))
314+ p = fig ._supylabel .get_position ()
315+ fig ._supylabel .set_position ((w_pad , p [1 ]))
316+ fig ._layoutgrid .edit_margin_min ('left' , bbox .width + 2 * w_pad )
294317
295318
296319def _match_submerged_margins (fig ):
0 commit comments