Skip to content

Commit a712590

Browse files
authored
Merge pull request #16694 from CSCD01-team20/16389-b
Lower Text's FontProperties priority when updating
2 parents 6cda8d0 + c986a12 commit a712590

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/matplotlib/tests/test_text.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,3 +653,12 @@ 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_kwarg_precedence():
659+
"""Test that kwargs take precedence over fontproperties defaults."""
660+
plt.figure()
661+
text1 = plt.xlabel("value", fontproperties='Times New Roman', size=40.0)
662+
text2 = plt.ylabel("counts", size=40.0, fontproperties='Times New Roman')
663+
assert text1.get_size() == 40.0
664+
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)