Skip to content

API: convert string fontsize to points immediately #7007

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 9 commits into from
Dec 12, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
API: convert string fontsize to points immediately
This bakes into the text artist (via the FontProperties) the default
fontsize at the time of creation.
  • Loading branch information
tacaswell committed Dec 12, 2016
commit 06dce269968b13af2b3c6370974f1ba331aa588f
8 changes: 6 additions & 2 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,10 @@ def set_size(self, size):
try:
size = float(size)
except ValueError:
if size is not None and size not in font_scalings:
try:
scale = font_scalings[size]
size = scale * FontManager.get_default_size()
Copy link
Member

Choose a reason for hiding this comment

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

I think it is better to move this line into else block.

except KeyError:
raise ValueError(
"Size is invalid. Valid font size are " + ", ".join(
str(i) for i in font_scalings.keys()))
Expand Down Expand Up @@ -942,7 +945,8 @@ def set_fontconfig_pattern(self, pattern):

def copy(self):
"""Return a deep copy of self"""
return FontProperties(_init = self)
return FontProperties(_init=self)


def ttfdict_to_fnames(d):
"""
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,15 @@ def test_agg_text_clip():
ax1.text(x, y, "foo", clip_on=True)
ax2.text(x, y, "foo")
plt.show()


@cleanup
def test_text_size_binding():
from matplotlib.font_manager import FontProperties

matplotlib.rcParams['font.size'] = 10
fp = FontProperties(size='large')
sz1 = fp.get_size_in_points()
matplotlib.rcParams['font.size'] = 100

assert sz1 == fp.get_size_in_points()