Skip to content

Commit 06dce26

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 4d59447 commit 06dce26

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/matplotlib/font_manager.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,10 @@ def set_size(self, size):
910910
try:
911911
size = float(size)
912912
except ValueError:
913-
if size is not None and size not in font_scalings:
913+
try:
914+
scale = font_scalings[size]
915+
size = scale * FontManager.get_default_size()
916+
except KeyError:
914917
raise ValueError(
915918
"Size is invalid. Valid font size are " + ", ".join(
916919
str(i) for i in font_scalings.keys()))
@@ -942,7 +945,8 @@ def set_fontconfig_pattern(self, pattern):
942945

943946
def copy(self):
944947
"""Return a deep copy of self"""
945-
return FontProperties(_init = self)
948+
return FontProperties(_init=self)
949+
946950

947951
def ttfdict_to_fnames(d):
948952
"""

lib/matplotlib/tests/test_text.py

+12
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,15 @@ def test_agg_text_clip():
399399
ax1.text(x, y, "foo", clip_on=True)
400400
ax2.text(x, y, "foo")
401401
plt.show()
402+
403+
404+
@cleanup
405+
def test_text_size_binding():
406+
from matplotlib.font_manager import FontProperties
407+
408+
matplotlib.rcParams['font.size'] = 10
409+
fp = FontProperties(size='large')
410+
sz1 = fp.get_size_in_points()
411+
matplotlib.rcParams['font.size'] = 100
412+
413+
assert sz1 == fp.get_size_in_points()

0 commit comments

Comments
 (0)