@@ -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,27 @@ 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', \
389
+ default: {ha}
388
390
The horizontal alignment of the text relative to (*x*, *y*).
389
391
390
- verticalalignment, va : { 'top', 'center', 'bottom', 'baseline'} , \
391
- default: 'top'
392
+ verticalalignment, va : 'top', 'center', 'bottom', 'baseline', \
393
+ default: {va}
392
394
The vertical alignment of the text relative to (*x*, *y*).
393
395
394
396
fontsize, size : default: :rc:`figure.titlesize`
@@ -401,8 +403,8 @@ def suptitle(self, t, **kwargs):
401
403
402
404
Returns
403
405
-------
404
- `.Text`
405
- The instance of the title .
406
+ text
407
+ The `.Text` instance of the {name} .
406
408
407
409
Other Parameters
408
410
----------------
@@ -415,19 +417,20 @@ def suptitle(self, t, **kwargs):
415
417
**kwargs
416
418
Additional kwargs are `matplotlib.text.Text` properties.
417
419
418
- Examples
419
- --------
420
- >>> fig.suptitle('This is the figure title', fontsize=12)
421
420
"""
421
+
422
422
manual_position = ('x' in kwargs or 'y' in kwargs )
423
+ suplab = getattr (self , info ['name' ])
423
424
424
- x = kwargs .pop ('x' , 0.5 )
425
- y = kwargs .pop ('y' , 0.98 )
425
+ x = kwargs .pop ('x' , info [ 'x0' ] )
426
+ y = kwargs .pop ('y' , info [ 'y0' ] )
426
427
427
428
if 'horizontalalignment' not in kwargs and 'ha' not in kwargs :
428
- kwargs ['horizontalalignment' ] = 'center'
429
+ kwargs ['horizontalalignment' ] = info [ 'ha' ]
429
430
if 'verticalalignment' not in kwargs and 'va' not in kwargs :
430
- kwargs ['verticalalignment' ] = 'top'
431
+ kwargs ['verticalalignment' ] = info ['va' ]
432
+ if 'rotation' not in kwargs :
433
+ kwargs ['rotation' ] = info ['rotation' ]
431
434
432
435
if 'fontproperties' not in kwargs :
433
436
if 'fontsize' not in kwargs and 'size' not in kwargs :
@@ -436,19 +439,45 @@ def suptitle(self, t, **kwargs):
436
439
kwargs ['weight' ] = mpl .rcParams ['figure.titleweight' ]
437
440
438
441
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 )
442
+ if suplab is not None :
443
+ suplab .set_text (t )
444
+ suplab .set_position ((x , y ))
445
+ suplab .update_from (sup )
443
446
sup .remove ()
444
447
else :
445
- self ._suptitle = sup
446
-
448
+ suplab = sup
447
449
if manual_position :
448
- self . _suptitle .set_in_layout (False )
449
-
450
+ suplab .set_in_layout (False )
451
+ setattr ( self , info [ 'name' ], suplab )
450
452
self .stale = True
451
- return self ._suptitle
453
+ return suplab
454
+
455
+ def
D966
suptitle (self , t , ** kwargs ):
456
+ # docstring from _suplabels...
457
+ info = {'name' : '_suptitle' , 'x0' : 0.5 , 'y0' : 0.98 ,
458
+ 'ha' : 'center' , 'va' : 'top' , 'rotation' : 0 }
459
+ return self ._suplabels (t , info , ** kwargs )
460
+
461
+ suptitle .__doc__ = _suplabels .__doc__ .format (
462
+ x0 = 0.5 , y0 = 0.98 , name = 'suptitle' , ha = 'center' , va = 'top' )
463
+
464
+ def supxlabel (self , t , ** kwargs ):
465
+ # docstring from _suplabels...
466
+ info = {'name' : '_supxlabel' , 'x0' : 0.5 , 'y0' : 0.01 ,
467
+ 'ha' : 'center' , 'va' : 'bottom' , 'rotation' : 0 }
468
+ return self ._suplabels (t , info , ** kwargs )
469
+
470
+ supxlabel .__doc__ = _suplabels .__doc__ .format (
471
+ x0 = 0.5 , y0 = 0.01 , name = 'supxlabel' , ha = 'center' , va = 'bottom' )
472
+
473
+ def supylabel (self , t , ** kwargs ):
474
+ # docstring from _suplabels...
475
+ info = {'name' : '_supylabel' , 'x0' : 0.02 , 'y0' : 0.5 ,
476
+ 'ha' : 'left' , 'va' : 'center' , 'rotation' : 90 }
477
+ return self ._suplabels (t , info , ** kwargs )
478
+
479
+ supylabel .__doc__ = _suplabels .__doc__ .format (
480
+ x0 = 0.02 , y0 = 0.5 , name = 'supylabel' , ha = 'left' , va = 'center' )
452
481
453
482
def get_edgecolor (self ):
454
483
"""Get the edge color of the Figure rectangle."""
@@ -2801,6 +2830,9 @@ def clf(self, keep_observers=False):
2801
2830
if not keep_observers :
2802
2831
self ._axobservers = cbook .CallbackRegistry ()
2803
2832
self ._suptitle = None
2833
+ self ._supxlabel = None
2834
+ self ._supylabel = None
2835
+
2804
2836
F438
if self .get_constrained_layout ():
2805
2837
self .init_layoutgrid ()
2806
2838
self .stale = True
0 commit comments