Skip to content

Commit 8d64fae

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 0f3dbc4 commit 8d64fae

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
@@ -404,3 +404,15 @@ def test_agg_text_clip():
404404
ax1.text(x, y, "foo", clip_on=True)
405405
ax2.text(x, y, "foo")
406406
plt.show()
407+
408+
409+
@cleanup
410+
def test_text_size_binding():
411+
from matplotlib.font_manager import FontProperties
412+
413+
matplotlib.rcParams['font.size'] = 10
414+
fp = FontProperties(size='large')
415+
sz1 = fp.get_size_in_points()
416+
matplotlib.rcParams['font.size'] = 100
417+
418+
assert sz1 == fp.get_size_in_points()

0 commit comments

Comments
 (0)