Skip to content

Commit 0191887

Browse files
Lower Text's FontProperties priority when updating
Co-authored-by: Robert Augustynowicz <[email protected]> Closes: matplotlib#16389
1 parent dbc35a9 commit 0191887

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎lib/matplotlib/tests/test_text.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,3 +653,11 @@ def test_buffer_size(fig_test, fig_ref):
653653
ax = fig_ref.add_subplot()
654654
ax.set_yticks([0, 1])
655655
ax.set_yticklabels(["€", ""])
656+
657+
658+
def test_fontproperties_presedence():
659+
plt.figure()
660+
text1 = plt.xlabel("value", fontproperties='Times New Roman', size=40.0)
661+
text2 = plt.ylabel("counts", size=40.0, fontproperties='Times New Roman')
662+
assert text1.get_size() == 40.0
663+
assert text2.get_size() == 40.0

‎lib/matplotlib/text.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ def __init__(self,
174174

175175
def update(self, kwargs):
176176
# docstring inherited
177-
# Update bbox last, as it depends on font properties.
178177
sentinel = object() # bbox can be None, so use another sentinel.
178+
# Update fontproperties first, as it has lowest priority.
179+
fontproperties = kwargs.pop("fontproperties", sentinel)
180+
if fontproperties is not sentinel:
181+
self.set_fontproperties(fontproperties)
182+
# Update bbox last, as it depends on font properties.
179183
bbox = kwargs.pop("bbox", sentinel)
180184
super().update(kwargs)
181185
if bbox is not sentinel:

0 commit comments

Comments
 (0)