@@ -233,6 +233,8 @@ def __init__(self):
233233 del self ._axes
234234
235235 self ._suptitle = None
236+ self ._supxlabel = None
237+ self ._supylabel = None
236238
237239 # constrained_layout:
238240 self ._layoutgrid = None
@@ -254,7 +256,6 @@ def __init__(self):
254256 self .images = []
255257 self .legends = []
256258 self .subfigs = []
257- self ._suptitle = None
258259 self .stale = True
259260 self .suppressComposite = None
260261
@@ -369,26 +370,26 @@ def get_window_extent(self, *args, **kwargs):
369370 """
370371 return self .bbox
371372
372- def suptitle (self , t , ** kwargs ):
373+ def _suplabels (self , t , info , ** kwargs ):
373374 """
374- Add a centered title to the figure.
375+ Add a centered {name} to the figure.
375376
376377 Parameters
377378 ----------
378379 t : str
379- The title text.
380+ The {name} text.
380381
381- x : float, default: 0.5
382+ x : float, default: {x0}
382383 The x location of the text in figure coordinates.
383384
384- y : float, default: 0.98
385+ y : float, default: {y0}
385386 The y location of the text in figure coordinates.
386387
387- horizontalalignment, ha : {'center', 'left', right'}, default: 'center'
388+ horizontalalignment, ha : {{ 'center', 'left', ' right'}} , default: {ha}
388389 The horizontal alignment of the text relative to (*x*, *y*).
389390
390- verticalalignment, va : {'top', 'center', 'bottom', 'baseline'}, \
391- default: 'top'
391+ verticalalignment, va : {{ 'top', 'center', 'bottom', 'baseline'} }, \
392+ default: {va}
392393 The vertical alignment of the text relative to (*x*, *y*).
393394
394395 fontsize, size : default: :rc:`figure.titlesize`
@@ -401,8 +402,8 @@ def suptitle(self, t, **kwargs):
401402
402403 Returns
403404 -------
404- `.Text`
405- The instance of the title .
405+ text
406+ The `.Text` instance of the {name} .
406407
407408 Other Parameters
408409 ----------------
@@ -415,19 +416,20 @@ def suptitle(self, t, **kwargs):
415416 **kwargs
416417 Additional kwargs are `matplotlib.text.Text` properties.
417418
418- Examples
419- --------
420- >>> fig.suptitle('This is the figure title', fontsize=12)
421419 """
420+
422421 manual_position = ('x' in kwargs or 'y' in kwargs )
422+ suplab = getattr (self , info ['name' ])
423423
424- x = kwargs .pop ('x' , 0.5 )
425- y = kwargs .pop ('y' , 0.98 )
424+ x = kwargs .pop ('x' , info [ 'x0' ] )
425+ y = kwargs .pop ('y' , info [ 'y0' ] )
426426
427427 if 'horizontalalignment' not in kwargs and 'ha' not in kwargs :
428- kwargs ['horizontalalignment' ] = 'center'
428+ kwargs ['horizontalalignment' ] = info [ 'ha' ]
429429 if 'verticalalignment' not in kwargs and 'va' not in kwargs :
430- kwargs ['verticalalignment' ] = 'top'
430+ kwargs ['verticalalignment' ] = info ['va' ]
431+ if 'rotation' not in kwargs :
432+ kwargs ['rotation' ] = info ['rotation' ]
431433
432434 if 'fontproperties' not in kwargs :
433435 if 'fontsize' not in kwargs and 'size' not in kwargs :
@@ -436,19 +438,46 @@ def suptitle(self, t, **kwargs):
436438 kwargs ['weight' ] = mpl .rcParams ['figure.titleweight' ]
437439
438440 sup = self .text (x , y , t , ** kwargs )
439- if self . _suptitle is not None :
440- self . _suptitle .set_text (t )
441- self . _suptitle .set_position ((x , y ))
442- self . _suptitle .update_from (sup )
441+ if suplab is not None :
442+ suplab .set_text (t )
443+ suplab .set_position ((x , y ))
444+ suplab .update_from (sup )
443445 sup .remove ()
444446 else :
445- self ._suptitle = sup
446-
447+ suplab = sup
447448 if manual_position :
448- self . _suptitle .set_in_layout (False )
449-
449+ suplab .set_in_layout (False )
450+ setattr ( self , info [ 'name' ], suplab )
450451 self .stale = True
451- return self ._suptitle
452+ return suplab
453+
454+ @docstring .Substitution (x0 = 0.5 , y0 = 0.98 , name = 'suptitle' , ha = 'center' ,
455+ va = 'top' )
456+ @docstring .copy (_suplabels )
457+ def suptitle (self , t , ** kwargs ):
458+ # docstring from _suplabels...
459+ info = {'name' : '_suptitle' , 'x0' : 0.5 , 'y0' : 0.98 ,
460+ 'ha' : 'center' , 'va' : 'top' , 'rotation' : 0 }
461+ return self ._suplabels (t , info , ** kwargs )
462+
463+ @docstring .Substitution (x0 = 0.5 , y0 = 0.01 , name = 'supxlabel' , ha = 'center' ,
464+ va = 'bottom' )
465+ @docstring .copy (_suplabels )
466+ def supxlabel (self , t , ** kwargs ):
467+ # docstring from _suplabels...
468+ info = {'name' : '_supxlabel' , 'x0' : 0.5 , 'y0' : 0.01 ,
469+ 'ha' : 'center' , 'va' : 'bottom' , 'rotation' : 0 }
470+ return self ._suplabels (t , info , ** kwargs )
471+
472+ @docstring .Substitution (x0 = 0.02 , y0 = 0.5 , name = 'supylabel' , ha = 'left' ,
473+ va = 'center' )
474+ @docstring .copy (_suplabels )
475+ def supylabel (self , t , ** kwargs ):
476+ # docstring from _suplabels...
477+ info = {'name' : '_supylabel' , 'x0' : 0.02 , 'y0' : 0.5 ,
478+ 'ha' : 'left' , 'va' : 'center' , 'rotation' : 'vertical' ,
479+ 'rotation_mode' : 'anchor' }
480+ return self ._suplabels (t , info , ** kwargs )
452481
453482 def get_edgecolor (self ):
454483 """Get the edge color of the Figure rectangle."""
@@ -2811,6 +2840,9 @@ def clf(self, keep_observers=False):
28112840 if not keep_observers :
28122841 self ._axobservers = cbook .CallbackRegistry ()
28132842 self ._suptitle = None
2843+ self ._supxlabel = None
2844+ self ._supylabel = None
2845+
28142846 if self .get_constrained_layout ():
28152847 self .init_layoutgrid ()
28162848 self .stale = True
0 commit comments