Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitfc5c6c4

Browse files
committed
Add rcparam for figure label size and weight
1 parent9926f06 commitfc5c6c4

File tree

6 files changed

+47
-12
lines changed

6 files changed

+47
-12
lines changed
Lines 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 separately from title
2+
-----------------------------------------------------------------------------
3+
4+
The figure labels, ``Figure.supxlabel`` and ``Figure.supylabel``, size and
5+
weight can be set separately from the figure title. Use:rc:`figure.labelsize`
6+
and: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

Lines 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'notinkwargs:
362362
if'fontsize'notinkwargsand'size'notinkwargs:
363-
kwargs['size']=mpl.rcParams['figure.titlesize']
363+
kwargs['size']=mpl.rcParams[info['size']]
364364
if'fontweight'notinkwargsand'weight'notinkwargs:
365-
kwargs['weight']=mpl.rcParams['figure.titleweight']
365+
kwargs['weight']=mpl.rcParams[info['weight']]
366366

367367
sup=self.text(x,y,t,**kwargs)
368368
ifsuplabisnotNone:
@@ -378,31 +378,34 @@ def _suplabels(self, t, info, **kwargs):
378378
returnsuplab
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
defsuptitle(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
returnself._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
defsupxlabel(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
returnself._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
defsupylabel(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
returnself._suplabels(t,info,**kwargs)
407410

408411
defget_edgecolor(self):

‎lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,8 @@
555555
## See https://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure
556556
#figure.titlesize: large # size of the figure title (``Figure.suptitle()``)
557557
#figure.titleweight: normal # weight of the figure title
558+
#figure.labelsize: large # size of the figure label (``Figure.sup[x|y]label()``)
559+
#figure.labelweight: normal # weight of the figure label
558560
#figure.figsize: 6.4, 4.8 # figure size in inches
559561
#figure.dpi: 100 # figure dots per inch
560562
#figure.facecolor: white # figure face color

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

Lines 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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,10 @@ def _convert_validator_spec(key, conv):
11321132
"figure.titlesize":validate_fontsize,
11331133
"figure.titleweight":validate_fontweight,
11341134

1135+
# figure labels
1136+
"figure.labelsize":validate_fontsize,
1137+
"figure.labelweight":validate_fontweight,
1138+
11351139
# figure size in inches: width by height
11361140
"figure.figsize":_listify_validator(validate_float,n=2),
11371141
"figure.dpi":validate_float,

‎lib/matplotlib/tests/test_figure.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,20 @@ def test_kwargs_pass():
13701370
assertsub_fig.get_label()=='sub figure'
13711371

13721372

1373+
@check_figures_equal(extensions=["png"])
1374+
deftest_rcparams(fig_test,fig_ref):
1375+
fig_ref.supxlabel("xlabel",weight='bold',size=15)
1376+
fig_ref.supylabel("ylabel",weight='bold',size=15)
1377+
fig_ref.suptitle("Title",weight='light',size=20)
1378+
withmpl.rc_context({'figure.labelweight':'bold',
1379+
'figure.labelsize':15,
1380+
'figure.titleweight':'light',
1381+
'figure.titlesize':20}):
1382+
fig_test.supxlabel("xlabel")
1383+
fig_test.supylabel("ylabel")
1384+
fig_test.suptitle("Title",weight='light')
1385+
1386+
13731387
deftest_deepcopy():
13741388
fig1,ax=plt.subplots()
13751389
ax.plot([0,1], [2,3])

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp