Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d7bd340

Browse files
authored
Merge pull request #11172 from jklymak/enh-rc-legend-title-fontsize6
ENH add rcparam to legend_title
2 parents c20b0c2 + 63714b4 commit d7bd340

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
Legend now has a title_fontsize kwarg
2-
-------------------------------------
1+
Legend now has a title_fontsize kwarg (and rcParam)
2+
---------------------------------------------------
33

44
The title for a `.Figure.legend` and `.Axes.legend` can now have its
5-
fontsize set via the ``title_fontsize`` kwarg, defaults to ``None``, which
6-
means the legend title will have the same fontsize as the axes default
7-
fontsize (*not* the legend fontsize, set by the ``fontsize`` kwarg or
5+
fontsize set via the ``title_fontsize`` kwarg. There is also a new
6+
:rc:`legend.title_fontsize`. Both default to ``None``, which means
7+
the legend title will have the same fontsize as the axes default fontsize
8+
(*not* the legend fontsize, set by the ``fontsize`` kwarg or
89
:rc:`legend.fontsize`).

lib/matplotlib/legend.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,9 @@ def __init__(self, parent, handles, labels,
543543

544544
self._loc = loc
545545
# figure out title fontsize:
546-
if title_fontsize is not None:
547-
tprop = FontProperties(size=title_fontsize)
548-
else:
549-
tprop = None
546+
if title_fontsize is None:
547+
title_fontsize = rcParams['legend.title_fontsize']
548+
tprop = FontProperties(size=title_fontsize)
550549
self.set_title(title, prop=tprop)
551550
self._last_fontsize_points = self._fontsize
552551
self._draggable = None

lib/matplotlib/rcsetup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,13 @@ def validate_aspect(s):
420420
raise ValueError('not a valid aspect specification')
421421

422422

423+
def validate_fontsize_None(s):
424+
if s is None or s == 'None':
425+
return None
426+
else:
427+
return validate_fontsize(s)
428+
429+
423430
def validate_fontsize(s):
424431
fontsizes = ['xx-small', 'x-small', 'small', 'medium', 'large',
425432
'x-large', 'xx-large', 'smaller', 'larger']
@@ -1226,6 +1233,7 @@ def _validate_linestyle(ls):
12261233
# the number of points in the legend line for scatter
12271234
'legend.scatterpoints': [1, validate_int],
12281235
'legend.fontsize': ['medium', validate_fontsize],
1236+
'legend.title_fontsize': [None, validate_fontsize_None],
12291237
# the relative size of legend markers vs. original
12301238
'legend.markerscale': [1.0, validate_float],
12311239
'legend.shadow': [False, validate_bool],

matplotlibrc.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ backend : $TEMPLATE_BACKEND
415415
#legend.scatterpoints : 1 ## number of scatter points
416416
#legend.markerscale : 1.0 ## the relative size of legend markers vs. original
417417
#legend.fontsize : medium
418+
#legend.title_fontsize : None ## None sets to the same as the default axes.
418419
## Dimensions as fraction of fontsize:
419420
#legend.borderpad : 0.4 ## border whitespace
420421
#legend.labelspacing : 0.5 ## the vertical space between the legend entries

0 commit comments

Comments
 (0)