Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bd60836

Browse filesBrowse files
committed
Add rcparam for figure label size and weight
1 parent 3a994d2 commit bd60836
Copy full SHA for bd60836

File tree

6 files changed

+47
-12
lines changed
Filter options

6 files changed

+47
-12
lines changed
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Allow setting figure label size and weight globally and separate from title
2+
---------------------------------------------------------------------------
3+
4+
The figure label, `Figure.supxlabel` and `Figure.supylabel`, size and weight
5+
can be set separately from the figure title. Use :rc:`figure.labelsize` and
6+
:rc:`figure.labelweight`.
7+
8+
Note that if you have locally changed :rc:`figure.titlesize` or
9+
:rc:`figure.titleweight`, you must perform the corresponding change for the
10+
introduced parameters for a consistent result.

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+15-12Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,10 @@ def _suplabels(self, t, info, **kwargs):
314314
verticalalignment, va : {'top', 'center', 'bottom', 'baseline'}, \
315315
default: %(va)s
316316
The vertical alignment of the text relative to (*x*, *y*).
317-
fontsize, size : default: :rc:`figure.titlesize`
317+
fontsize, size : default: :rc:`figure.%(rc)ssize`
318318
The font size of the text. See `.Text.set_size` for possible
319319
values.
320-
fontweight, weight : default: :rc:`figure.titleweight`
320+
fontweight, weight : default: :rc:`figure.%(rc)sweight`
321321
The font weight of the text. See `.Text.set_weight` for possible
322322
values.
323323
@@ -331,8 +331,8 @@ def _suplabels(self, t, info, **kwargs):
331331
fontproperties : None or dict, optional
332332
A dict of font properties. If *fontproperties* is given the
333333
default values for font size and weight are taken from the
334-
`.FontProperties` defaults. :rc:`figure.titlesize` and
335-
:rc:`figure.titleweight` are ignored in this case.
334+
`.FontProperties` defaults. :rc:`figure.%(rc)ssize` and
335+
:rc:`figure.%(rc)sweight` are ignored in this case.
336336
337337
**kwargs
338338
Additional kwargs are `matplotlib.text.Text` properties.
@@ -360,9 +360,9 @@ def _suplabels(self, t, info, **kwargs):
360360

361361
if 'fontproperties' not in kwargs:
362362
if 'fontsize' not in kwargs and 'size' not in kwargs:
363-
kwargs['size'] = mpl.rcParams['figure.titlesize']
363+
kwargs['size'] = mpl.rcParams[info['size']]
364364
if 'fontweight' not in kwargs and 'weight' not in kwargs:
365-
kwargs['weight'] = mpl.rcParams['figure.titleweight']
365+
kwargs['weight'] = mpl.rcParams[info['weight']]
366366

367367
sup = self.text(x, y, t, **kwargs)
368368
if suplab is not None:
@@ -378,31 +378,34 @@ def _suplabels(self, t, info, **kwargs):
378378
return suplab
379379

380380
@docstring.Substitution(x0=0.5, y0=0.98, name='suptitle', ha='center',
381-
va='top')
381+
va='top', rc='title')
382382
@docstring.copy(_suplabels)
383383
def suptitle(self, t, **kwargs):
384384
# docstring from _suplabels...
385385
info = {'name': '_suptitle', 'x0': 0.5, 'y0': 0.98,
386-
'ha': 'center', 'va': 'top', 'rotation': 0}
386+
'ha': 'center', 'va': 'top', 'rotation': 0,
387+
'size': 'figure.titlesize', 'weight': 'figure.titleweight'}
387388
return self._suplabels(t, info, **kwargs)
388389

389390
@docstring.Substitution(x0=0.5, y0=0.01, name='supxlabel', ha='center',
390-
va='bottom')
391+
va='bottom', rc='label')
391392
@docstring.copy(_suplabels)
392393
def supxlabel(self, t, **kwargs):
393394
# docstring from _suplabels...
394395
info = {'name': '_supxlabel', 'x0': 0.5, 'y0': 0.01,
395-
'ha': 'center', 'va': 'bottom', 'rotation': 0}
396+
'ha': 'center', 'va': 'bottom', 'rotation': 0,
397+
'size': 'figure.labelsize', 'weight': 'figure.labelweight'}
396398
return self._suplabels(t, info, **kwargs)
397399

398400
@docstring.Substitution(x0=0.02, y0=0.5, name='supylabel', ha='left',
399-
va='center')
401+
va='center', rc='label')
400402
@docstring.copy(_suplabels)
401403
def supylabel(self, t, **kwargs):
402404
# docstring from _suplabels...
403405
info = {'name': '_supylabel', 'x0': 0.02, 'y0': 0.5,
404406
'ha': 'left', 'va': 'center', 'rotation': 'vertical',
405-
'rotation_mode': 'anchor'}
407+
'rotation_mode': 'anchor', 'size': 'figure.labelsize',
408+
'weight': 'figure.labelweight'}
406409
return self._suplabels(t, info, **kwargs)
407410

408411
def get_edgecolor(self):

‎lib/matplotlib/mpl-data/matplotlibrc

Copy file name to clipboardExpand all lines: lib/matplotlib/mpl-data/matplotlibrc
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@
546546
## See https://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure
547547
#figure.titlesize: large # size of the figure title (``Figure.suptitle()``)
548548
#figure.titleweight: normal # weight of the figure title
549+
#figure.labelsize: large # size of the figure label (``Figure.sup[x|y]label()``)
550+
#figure.labelweight: normal # weight of the figure label
549551
#figure.figsize: 6.4, 4.8 # figure size in inches
550552
#figure.dpi: 100 # figure dots per inch
551553
#figure.facecolor: white # figure face color

‎lib/matplotlib/mpl-data/stylelib/classic.mplstyle

Copy file name to clipboardExpand all lines: lib/matplotlib/mpl-data/stylelib/classic.mplstyle
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ legend.edgecolor : inherit # legend edge color (when 'inherit' uses axes.e
307307
# See https://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure
308308
figure.titlesize : medium # size of the figure title
309309
figure.titleweight : normal # weight of the figure title
310+
figure.labelsize: medium # size of the figure label
311+
figure.labelweight: normal # weight of the figure label
310312
figure.figsize : 8, 6 # figure size in inches
311313
figure.dpi : 80 # figure dots per inch
312314
figure.facecolor : 0.75 # figure facecolor; 0.75 is scalar gray

‎lib/matplotlib/rcsetup.py

Copy file name to clipboardExpand all lines: lib/matplotlib/rcsetup.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,10 @@ def _convert_validator_spec(key, conv):
11161116
"figure.titlesize": validate_fontsize,
11171117
"figure.titleweight": validate_fontweight,
11181118

1119+
# figure labels
1120+
"figure.labelsize": validate_fontsize,
1121+
"figure.labelweight": validate_fontweight,
1122+
11191123
# figure size in inches: width by height
11201124
"figure.figsize": _listify_validator(validate_float, n=2),
11211125
"figure.dpi": validate_float,

‎lib/matplotlib/tests/test_figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_figure.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,20 @@ def test_kwargs_pass():
12851285
assert sub_fig.get_label() == 'sub figure'
12861286

12871287

1288+
@check_figures_equal(extensions=["png"])
1289+
def test_rcparams(fig_test, fig_ref):
1290+
fig_ref.supxlabel("xlabel", weight='bold', size=15)
1291+
fig_ref.supylabel("ylabel", weight='bold', size=15)
1292+
fig_ref.suptitle("Title", weight='light', size=20)
1293+
with mpl.rc_context({'figure.labelweight': 'bold',
1294+
'figure.labelsize': 15,
1295+
'figure.titleweight': 'light',
1296+
'figure.titlesize': 20}):
1297+
fig_test.supxlabel("xlabel")
1298+
fig_test.supylabel("ylabel")
1299+
fig_test.suptitle("Title", weight='light')
1300+
1301+
12881302
def test_deepcopy():
12891303
fig1, ax = plt.subplots()
12901304
ax.plot([0, 1], [2, 3])

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.