Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 06dce26

Browse filesBrowse 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
Copy full SHA for 06dce26

File tree

Expand file treeCollapse file tree

2 files changed

+18
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-2
lines changed

‎lib/matplotlib/font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/font_manager.py
+6-2Lines changed: 6 additions & 2 deletions
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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_text.py
+12Lines changed: 12 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.