Skip to content

Commit b9da1f6

Browse files
committed
FIX: make suptitle be in CL only if placed automatically
1 parent 64880fa commit b9da1f6

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

lib/matplotlib/_constrained_layout.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
238238
ax._poslayoutbox.constrain_left_margin(0, strength='weak')
239239

240240
# do layout for suptitle.
241-
if fig._suptitle is not None:
241+
if fig._suptitle is not None and fig._suptitle._layoutbox is not None:
242242
sup = fig._suptitle
243243
bbox = invTransFig(sup.get_window_extent(renderer=renderer))
244244
height = bbox.y1 - bbox.y0

lib/matplotlib/figure.py

+20-10
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,11 @@ def suptitle(self, t, *, x=.5, y=.98, **kwargs):
731731
732732
>>> fig.suptitle('This is the figure title', fontsize=12)
733733
"""
734+
manual_position = ('x' in kwargs or 'y' in kwargs)
735+
736+
x = kwargs.pop('x', 0.5)
737+
y = kwargs.pop('y', 0.98)
738+
734739
if ('horizontalalignment' not in kwargs) and ('ha' not in kwargs):
735740
kwargs['horizontalalignment'] = 'center'
736741
if ('verticalalignment' not in kwargs) and ('va' not in kwargs):
@@ -751,17 +756,22 @@ def suptitle(self, t, *, x=.5, y=.98, **kwargs):
751756
else:
752757
self._suptitle = sup
753758
if self._layoutbox is not None:
754-
figlb = self._layoutbox
755-
self._suptitle._layoutbox = layoutbox.LayoutBox(
756-
parent=figlb,
759+
if not manual_position:
760+
figlb = self._layoutbox
761+
self._suptitle._layoutbox = \
762+
layoutbox.LayoutBox(parent=figlb,
757763
name=figlb.name+'.suptitle')
758-
for child in figlb.children:
759-
if not (child == self._suptitle._layoutbox):
760-
w_pad, h_pad, wspace, hspace = \
761-
self.get_constrained_layout_pads(
762-
relative=True)
763-
layoutbox.vstack([self._suptitle._layoutbox, child],
764-
padding=h_pad*2., strength='required')
764+
for child in figlb.children:
765+
if not (child == self._suptitle._layoutbox):
766+
w_pad, h_pad, wspace, hspace = \
767+
self.get_constrained_layout_pads(
768+
relative=True)
769+
layoutbox.vstack([self._suptitle._layoutbox,
770+
child],
771+
padding=h_pad*2.,
772+
strength='required')
773+
else:
774+
self._suptitle._layoutbox = None
765775
self.stale = True
766776
return self._suptitle
767777

0 commit comments

Comments
 (0)