@@ -233,6 +233,8 @@ def __init__(self):
233
233
del self ._axes
234
234
235
235
self ._suptitle = None
236
+ self ._supxlabel = None
237
+ self ._supylabel = None
236
238
237
239
# constrained_layout:
238
240
self ._layoutgrid = None
@@ -254,7 +256,6 @@ def __init__(self):
254
256
self .images = []
255
257
self .legends = []
256
258
self .subfigs = []
257
- self ._suptitle = None
258
259
self .stale = True
259
260
self .suppressComposite = None
260
261
@@ -369,26 +370,26 @@ def get_window_extent(self, *args, **kwargs):
369
370
"""
370
371
return self .bbox
371
372
372
- def suptitle (self , t , ** kwargs ):
373
+ def _suplabels (self , t , info , ** kwargs ):
373
374
"""
374
- Add a centered title to the figure.
375
+ Add a centered {name} to the figure.
375
376
376
377
Parameters
377
378
----------
378
379
t : str
379
- The title text.
380
+ The {name} text.
380
381
381
- x : float, default: 0.5
382
+ x : float, default: {x0}
382
383
The x location of the text in figure coordinates.
383
384
384
- y : float, default: 0.98
385
+ y : float, default: {y0}
385
386
The y location of the text in figure coordinates.
386
387
387
- horizontalalignment, ha : {'center', 'left', right'}, default: 'center'
388
+ horizontalalignment, ha : {{ 'center', 'left', ' right'}} , default: {ha}
388
389
The horizontal alignment of the text relative to (*x*, *y*).
389
390
390
- verticalalignment, va : {'top', 'center', 'bottom', 'baseline'}, \
391
- default: 'top'
391
+ verticalalignment, va : {{ 'top', 'center', 'bottom', 'baseline'} }, \
392
+ default: {va}
392
393
The vertical alignment of the text relative to (*x*, *y*).
393
394
394
395
fontsize, size : default: :rc:`figure.titlesize`
@@ -401,8 +402,8 @@ def suptitle(self, t, **kwargs):
401
402
402
403
Returns
403
404
-------
404
- `.Text`
405
- The instance of the title .
405
+ text
406
+ The `.Text` instance of the {name} .
406
407
407
408
Other Parameters
408
409
----------------
@@ -415,19 +416,20 @@ def suptitle(self, t, **kwargs):
415
416
**kwargs
416
417
Additional kwargs are `matplotlib.text.Text` properties.
417
418
418
- Examples
419
- --------
420
- >>> fig.suptitle('This is the figure title', fontsize=12)
421
419
"""
420
+
422
421
manual_position = ('x' in kwargs or 'y' in kwargs )
422
+ suplab = getattr (self , info ['name' ])
423
423
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' ] )
426
426
427
427
if 'horizontalalignment' not in kwargs and 'ha' not in kwargs :
428
- kwargs ['horizontalalignment' ] = 'center'
428
+ kwargs ['horizontalalignment' ] = info [ 'ha' ]
429
429
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' ]
431
433
432
434
if 'fontproperties' not in kwargs :
433
435
if 'fontsize' not in kwargs and 'size' not in kwargs :
@@ -436,19 +438,46 @@ def suptitle(self, t, **kwargs):
436
438
kwargs ['weight' ] = mpl .rcParams ['figure.titleweight' ]
437
439
438
440
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 )
443
445
sup .remove ()
444
446
else :
445
- self ._suptitle = sup
446
-
447
+ suplab = sup
447
448
if manual_position :
448
- self . _suptitle .set_in_layout (False )
449
-
449
+ suplab .set_in_layout (False )
450
+ setattr ( self , info [ 'name' ], suplab )
450
451
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 )
452
481
453
482
def get_edgecolor (self ):
454
483
"""Get the edge color of the Figure rectangle."""
@@ -2811,6 +2840,9 @@ def clf(self, keep_observers=False):
2811
2840
if not keep_observers :
2812
2841
self ._axobservers = cbook .CallbackRegistry ()
2813
2842
self ._suptitle = None
2843
+ self ._supxlabel = None
2844
+ self ._supylabel = None
2845
+
2814
2846
if self .get_constrained_layout ():
2815
2847
self .init_layoutgrid ()
2816
2848
self .stale = True
0 commit comments