@@ -678,7 +678,7 @@ def get_window_extent(self, *args, **kwargs):
678
678
"""
679
679
return self .bbox
680
680
681
- def suptitle (self , t , * , x = .5 , y = .98 , * *kwargs ):
681
+ def suptitle (self , t , ** kwargs ):
682
682
"""
683
683
Add a centered title to the figure.
684
684
@@ -732,6 +732,11 @@ def suptitle(self, t, *, x=.5, y=.98, **kwargs):
732
732
733
733
>>> fig.suptitle('This is the figure title', fontsize=12)
734
734
"""
735
+ manual_position = ('x' in kwargs or 'y' in kwargs )
736
+
737
+ x = kwargs .pop ('x' , 0.5 )
738
+ y = kwargs .pop ('y' , 0.98 )
739
+
735
740
if ('horizontalalignment' not in kwargs ) and ('ha' not in kwargs ):
736
741
kwargs ['horizontalalignment' ] = 'center'
737
742
if ('verticalalignment' not in kwargs ) and ('va' not in kwargs ):
@@ -751,19 +756,22 @@ def suptitle(self, t, *, x=.5, y=.98, **kwargs):
751
756
sup .remove ()
752
757
else :
753
758
self ._suptitle = sup
754
- if self ._layoutbox is not None :
755
- # assign a layout box to the suptitle...
756
- figlb = self ._layoutbox
757
- self ._suptitle ._layoutbox = layoutbox .LayoutBox (
758
- parent = figlb ,
759
- name = figlb .name + '.suptitle' )
760
- for child in figlb .children :
761
- if not (child == self ._suptitle ._layoutbox ):
762
- w_pad , h_pad , wspace , hspace = \
763
- self .get_constrained_layout_pads (
764
- relative = True )
765
- layoutbox .vstack ([self ._suptitle ._layoutbox , child ],
766
- padding = h_pad * 2. , strength = 'required' )
759
+ self ._suptitle ._layoutbox = None
760
+ if self ._layoutbox is not None and not manual_position :
761
+ w_pad , h_pad , wspace , hspace = \
762
+ self .get_constrained_layout_pads (relative = True )
763
+ figlb = self ._layoutbox
764
+ self ._suptitle ._layoutbox = layoutbox .LayoutBox (
765
+ parent = figlb , artist = self ._suptitle ,
766
+ name = figlb .name + '.suptitle' )
767
+ # stack the suptitle on top of all the children.
768
+ # Some day this should be on top of all the children in the
769
+ # gridspec only.
770
+ for child in figlb .children :
771
+ if child is not self ._suptitle ._layoutbox :
772
+ layoutbox .vstack ([self ._suptitle ._layoutbox ,
773
+ child ],
774
+ padding = h_pad * 2. , strength = 'required' )
767
775
self .stale = True
768
776
return self ._suptitle
769
777
0 commit comments