Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,15 @@ def _remove_suplabel(self, label, name):
@_docstring.copy(_suplabels)
def suptitle(self, t, **kwargs):
# docstring from _suplabels...
info = {'name': '_suptitle', 'x0': 0.5, 'y0': 0.98,
'ha': 'center', 'va': 'top', 'rotation': 0,
# Use rcParams for defaults, with backward-compatible fallbacks
ha = mpl.rcParams.get('figure.titleloc', 'center')
va = mpl.rcParams.get('figure.titleva', 'top')
y0 = mpl.rcParams.get('figure.titleh', 0.98)
# Map location to x position for 'center', 'left', 'right'
loc_to_x = {'center': 0.5, 'left': 0.0, 'right': 1.0}
x0 = loc_to_x.get(ha, 0.5)
info = {'name': '_suptitle', 'x0': x0, 'y0': y0,
'ha': ha, 'va': va, 'rotation': 0,
'size': 'figure.titlesize', 'weight': 'figure.titleweight'}
return self._suplabels(t, info, **kwargs)

Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/mpl-data/matplotlibrc
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@
## See https://matplotlib.org/stable/api/figure_api.html#matplotlib.figure.Figure
#figure.titlesize: large # size of the figure title (``Figure.suptitle()``)
#figure.titleweight: normal # weight of the figure title
#figure.titleloc: center # horizontal location of the figure title
#figure.titleh: 0.98 # vertical position of the figure title
#figure.titleva: top # vertical alignment of the figure title
#figure.labelsize: large # size of the figure label (``Figure.sup[x|y]label()``)
#figure.labelweight: normal # weight of the figure label
#figure.figsize: 6.4, 4.8 # figure size in inches
Expand Down
21 changes: 21 additions & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,9 @@ def _convert_validator_spec(key, conv):
# figure title
"figure.titlesize": validate_fontsize,
"figure.titleweight": validate_fontweight,
"figure.titleloc": ["center", "left", "right"],
"figure.titleh": validate_float,
"figure.titleva": ["top", "center", "bottom", "baseline"],

# figure labels
"figure.labelsize": validate_fontsize,
Expand Down Expand Up @@ -2638,6 +2641,24 @@ class _Param:
validator=validate_fontweight,
description="weight of the figure title"
),
_Param(
"figure.titleloc",
default="center",
validator=["center", "left", "right"],
description="horizontal location of the figure title (``Figure.suptitle()``)"
),
_Param(
"figure.titleh",
default=0.98,
validator=validate_float,
description="vertical position of the figure title in figure coordinates"
),
_Param(
"figure.titleva",
default="top",
validator=["top", "center", "bottom", "baseline"],
description="vertical alignment of the figure title"
),
_Param(
"figure.labelsize",
default="large",
Expand Down
Loading