Skip to content
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

ENH: add title_fontsize to legend #10715

Merged
merged 2 commits into from
May 4, 2018

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Mar 8, 2018

PR Summary

closes #8699

In master, a legend will have the fontsize of the title, set by the default axes fontsize, and will ignore the fontsize kwarg for legend:

import matplotlib.pyplot as plt
import matplotlib as mpl

fig, ax = plt.subplots(figsize=(8, 3))
ax.plot([1, 2], label='Boo')
ax.legend(title="Legend Title", fontsize=6)
plt.show()

fig1

Here we implement the title_fontsize kwarg:

ax.legend(title="Legend Title", fontsize=6, title_fontsize=6)

fig2

and the :rc:legend.title_fontsize rcParam:

mpl.rcParams['title_fontsize']=6
ax.legend(title="Legend Title", fontsize=6)

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)

@@ -471,6 +471,7 @@ def test_if_rctemplate_would_be_valid(tmpdir):
with open(fname, "w") as f:
f.writelines(newlines)
with pytest.warns(None) as record:
print(fname)
Copy link
Member

Choose a reason for hiding this comment

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

Is this print intended?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, thanks for catching that.

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

conditionally on CI

@jklymak
Copy link
Member Author

jklymak commented Apr 12, 2018

Rebased...

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

Anyone can dismiss this once handled.

# figure out title fontsize:
if title_fontsize is None:
title_fontsize = rcParams['legend.title_fontsize']
print(self.prop)
Copy link
Contributor

Choose a reason for hiding this comment

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

remove that print

@jklymak jklymak force-pushed the enh-rc-legend-title-fontsize branch from 3d810eb to f84982d Compare May 4, 2018 17:43
@anntzer
Copy link
Contributor

anntzer commented May 4, 2018

Frankly I'm not particularly keen on the rcparam (then we'll get title.fontstyle, title.fontfamily, etc?) and would rather have one pass in a fontproperties (see also #10249 for my thoughts on that matter), but I accept that practicality purity etc :-)

@jklymak jklymak force-pushed the enh-rc-legend-title-fontsize branch from 31e1d88 to 03742ea Compare May 4, 2018 17:52
@jklymak
Copy link
Member Author

jklymak commented May 4, 2018

I could be easily convinced to leave the rcparam out. I never set anything via rcparam as I think it kills reproducibility.

@jklymak jklymak force-pushed the enh-rc-legend-title-fontsize branch from 03742ea to 156131c Compare May 4, 2018 18:04
anntzer
anntzer previously approved these changes May 4, 2018
@anntzer anntzer dismissed their stale review May 4, 2018 18:12

Let's leave the rcparam out then for now at least.

@jklymak jklymak force-pushed the enh-rc-legend-title-fontsize branch from 0c39ad6 to fcdf8c3 Compare May 4, 2018 20:25
@anntzer anntzer merged commit dd5f241 into matplotlib:master May 4, 2018
@jklymak
Copy link
Member Author

jklymak commented May 4, 2018

Note that this kind of stomped on #10121. My appologies @Raab70 - I should have remembered that PR....

@jklymak jklymak mentioned this pull request May 4, 2018
6 tasks
@jolespin
Copy link

jolespin commented Nov 3, 2020

Are there any plans to make a title_fontweight argument?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make legend title fontsize obey fontsize kwarg by default?
4 participants