Skip to content

Commit dbf9c62

Browse files
committed
API: convert string fontsize to points immediately
This bakes into the text artist (via the FontProperties) the default fontsize at the time of creation.
1 parent b3d33ef commit dbf9c62

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/matplotlib/font_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,10 @@ def set_size(self, size):
909909
try:
910910
size = float(size)
911911
except ValueError:
912-
if size is not None and size not in font_scalings:
912+
try:
913+
scale = font_scalings[size]
914+
size = scale * FontManager.get_default_size()
915+
except KeyError:
913916
raise ValueError(
914917
"Size is invalid. Valid font size are " + ", ".join(
915918
str(i) for i in font_scalings.keys()))
@@ -941,7 +944,8 @@ def set_fontconfig_pattern(self, pattern):
941944

942945
def copy(self):
943946
"""Return a deep copy of self"""
944-
return FontProperties(_init = self)
947+
return FontProperties(_init=self)
948+
945949

946950
def ttfdict_to_fnames(d):
947951
"""

lib/matplotlib/tests/test_text.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,15 @@ def test_text_stale():
393393
assert not ax1.stale
394394
assert not ax2.stale
395395
assert not fig.stale
396+
397+
398+
@cleanup
399+
def test_text_size_binding():
400+
from matplotlib.font_manager import FontProperties
401+
402+
matplotlib.rcParams['font.size'] = 10
403+
fp = FontProperties(size='large')
404+
sz1 = fp.get_size_in_points()
405+
matplotlib.rcParams['font.size'] = 100
406+
407+
assert sz1 == fp.get_size_in_points()

0 commit comments

Comments
 (0)