8000 ENH add rcparam to legend_title by jklymak · Pull Request #11172 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

ENH add rcparam to legend_title #11172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2018
Merged
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: 6 additions & 5 deletions doc/users/next_whats_new/legend_title_fontsize_kwarg.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Legend now has a title_fontsize kwarg
-------------------------------------
Legend now has a title_fontsize kwarg (and rcParam)
---------------------------------------------------

The title for a `.Figure.legend` and `.Axes.legend` can now have its
fontsize set via the ``title_fontsize`` kwarg, defaults to ``None``, which
means the legend title will have the same fontsize as the axes default
fontsize (*not* the legend fontsize, set by the ``fontsize`` kwarg or
fontsize set via the ``title_fontsize`` kwarg. There is also a new
:rc:`legend.title_fontsize`. Both default to ``None``, which means
the legend title will have the same fontsize as the axes default fontsize
(*not* the legend fontsize, set by the ``fontsize`` kwarg or
:rc:`legend.fontsize`).
7 changes: 3 additions & 4 deletions lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,9 @@ def __init__(self, parent, handles, labels,

self._loc = loc
# figure out title fontsize:
if title_fontsize is not None:
tprop = FontProperties(size=title_fontsize)
else:
tprop = None
if title_fontsize is None:
title_fontsize = rcParams['legend.title_fontsize']
tprop = FontProperties(size=title_fontsize)
self.set_title(title, prop=tprop)
self._last_fontsize_points = self._fontsize
self._draggable = None
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,13 @@ def validate_aspect(s):
raise ValueError('not a valid aspect specification')


def validate_fontsize_None(s):
if s is None or s == 'None':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should s == 'none' be acceptable too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied float_or_None; I think this is here because when you type "None" in the matplotlibrc it comes back as a string. So I'd argue that should be "None" and not allow "none".

return None
else:
return validate_fontsize(s)


def validate_fontsize(s):
fontsizes = ['xx-small', 'x-small', 'small', 'medium', 'large',
'x-large', 'xx-large', 'smaller', 'larger']
Expand Down Expand Up @@ -1226,6 +1233,7 @@ def _validate_linestyle(ls):
# the number of points in the legend line for scatter
'legend.scatterpoints': [1, validate_int],
'legend.fontsize': ['medium', validate_fontsize],
'legend.title_fontsize': [None, validate_fontsize_None],
# the relative size of legend markers vs. original
'legend.markerscale': [1.0, validate_float],
'legend.shadow': [False, validate_bool],
Expand Down
1 change: 1 addition & 0 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ backend : $TEMPLATE_BACKEND
#legend.scatterpoints : 1 ## number of scatter points
#legend.markerscale : 1.0 ## the relative size of legend markers vs. original
#legend.fontsize : medium
#legend.title_fontsize : None ## None sets to the same as the default axes.
## Dimensions as fraction of fontsize:
#legend.borderpad : 0.4 ## border whitespace
#legend.labelspacing : 0.5 ## the vertical space between the legend entries
Expand Down
0