@@ -662,26 +662,27 @@ def get_window_extent(self, *args, **kwargs):
662
662
"""
663
663
return self .bbox
664
664
665
- def suptitle (self , t , ** kwargs ):
665
+ def _suplabels (self , t , info , ** kwargs ):
666
666
"""
667
- Add a centered title to the figure.
667
+ Add a centered {name} to the figure.
668
668
669
669
Parameters
670
670
----------
671
671
t : str
672
- The title text.
672
+ The {name} text.
673
673
674
- x : float, default 0.5
674
+ x : float, default {x0}
675
675
The x location of the text in figure coordinates.
676
676
677
- y : float, default 0.98
677
+ y : float, default {y0}
678
678
The y location of the text in figure coordinates.
679
679
680
- horizontalalignment, ha : {'center', 'left', right'}, default: 'center'
680
+ horizontalalignment, ha : 'center', 'left', 'right', \
681
+ default: {ha}
681
682
The horizontal alignment of the text relative to (*x*, *y*).
682
683
683
- verticalalignment, va : { 'top', 'center', 'bottom', 'baseline'} , \
684
- default: 'top'
684
+ verticalalignment, va : 'top', 'center', 'bottom', 'baseline', \
685
+ default: {va}
685
686
The vertical alignment of the text relative to (*x*, *y*).
686
687
687
688
fontsize, size : default: :rc:`figure.titlesize`
@@ -695,7 +696,7 @@ def suptitle(self, t, **kwargs):
695
696
Returns
696
697
-------
697
698
text
698
- The `.Text` instance of the title .
699
+ The `.Text` instance of the {name} .
699
700
700
701
Other Parameters
701
702
----------------
@@ -708,19 +709,20 @@ def suptitle(self, t, **kwargs):
708
709
**kwargs
709
710
Additional kwargs are `matplotlib.text.Text` properties.
710
711
711
- Examples
712
- --------
713
- >>> fig.suptitle('This is the figure title', fontsize=12)
714
712
"""
713
+
715
714
manual_position = ('x' in kwargs or 'y' in kwargs )
715
+ suplab = getattr (self , info ['name' ])
716
716
717
- x = kwargs .pop ('x' , 0.5 )
718
- y = kwargs .pop ('y' , 0.98 )
717
+ x = kwargs .pop ('x' , info [ 'x0' ] )
718
+ y = kwargs .pop ('y' , info [ 'y0' ] )
719
719
720
720
if 'horizontalalignment' not in kwargs and 'ha' not in kwargs :
721
- kwargs ['horizontalalignment' ] = 'center'
721
+ kwargs ['horizontalalignment' ] = info [ 'ha' ]
722
722
if 'verticalalignment' not in kwargs and 'va' not in kwargs :
723
- kwargs ['verticalalignment' ] = 'top'
723
+ kwargs ['verticalalignment' ] = info ['va' ]
724
+ if 'rotation' not in kwargs :
725
+ kwargs ['rotation' ] = info ['rotation' ]
724
726
725
727
if 'fontproperties' not in kwargs :
726
728
if 'fontsize' not in kwargs and 'size' not in kwargs :
@@ -729,17 +731,46 @@ def suptitle(self, t, **kwargs):
729
731
kwargs ['weight' ] = mpl .rcParams ['figure.titleweight' ]
730
732
731
733
sup = self .text (x , y , t , ** kwargs )
732
- if self . _suptitle is not None :
733
- self . _suptitle .set_text (t )
734
- self . _suptitle .set_position ((x , y ))
735
- self . _suptitle .update_from (sup )
734
+ if suplab is not None :
735
+ suplab .set_text (t )
736
+ suplab .set_position ((x , y ))
737
+ suplab .update_from (sup )
736
738
sup .remove ()
737
739
else :
738
- self . _suptitle = sup
740
+ suplab = sup
739
741
if manual_position :
740
- self ._suptitle .set_in_layout (False )
742
+ suplab .set_in_layout (False )
743
+ setattr (self , info ['name' ], suplab )
741
744
self .stale = True
742
- return self ._suptitle
745
+ return suplab
746
+
747
+ def suptitle (self , t , ** kwargs ):
748
+ # docstring from _suplabels...
749
+ info = {'name' : '_suptitle' , 'x0' : 0.5 , 'y0' : 0.98 ,
750
+ 'ha' : 'center' , 'va' : 'top' , 'rotation' : 0 }
751
+ return self ._suplabels (t , info , ** kwargs )
752
+
753
+ suptitle .__doc__ = _suplabels .__doc__ .format (
754
+ x0 = 0.5 , y0 = 0.98 , name = 'suptitle' , ha = 'center' , va = 'top' )
755
+
756
+ def supxlabel (self , t , ** kwargs ):
757
+ # docstring from _suplabels...
758
+ info = {'name' : '_supxlabel' , 'x0' : 0.5 , 'y0' : 0.01 ,
759
+ 'ha' : 'center' , 'va' : 'bottom' , 'rotation' : 0 }
760
+ return self ._suplabels (t , info , ** kwargs )
761
+
762
+ supxlabel .__doc__ = _suplabels .__doc__ .format (
763
+ x0 = 0.5 , y0 = 0.01 , name = 'supxlabel' , ha = 'center' , va = 'bottom' )
764
+
765
+ def supylabel (self , t , ** kwargs ):
766
+ # docstring from _suplabels...
767
+ info = {'name' : '_supylabel' , 'x0' : 0.02 , 'y0' : 0.5 ,
768
+ 'ha' : 'left' , 'va' : 'center' , 'rotation' : 90 }
769
+ return self ._suplabels (t , info , ** kwargs )
770
+
771
+ supylabel .__doc__ = _suplabels .__doc__ .format (
772
+ x0 = 0.02 , y0 = 0.5 , name = 'supylabel' , ha = 'left' , va = 'center' )
773
+
743
774
744
775
def set_canvas (self , canvas ):
745
776
"""
@@ -1603,6 +1634,8 @@ def clf(self, keep_observers=False):
1603
1634
if not keep_observers :
1604
1635
self ._axobservers = cbook .CallbackRegistry ()
1605
1636
self ._suptitle = None
1637
+ self ._supxlabel = None
1638
+ self ._supylabel = None
1606
1639
if self .get_constrained_layout ():
1607
1640
layoutgrid .nonetree (self ._layoutgrid )
1608
1641
self .stale = True
0 commit comments