Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,3 +653,12 @@ def test_buffer_size(fig_test, fig_ref):
ax = fig_ref.add_subplot()
ax.set_yticks([0, 1])
ax.set_yticklabels(["€", ""])


def test_fontproperties_kwarg_precedence():
"""Test that kwargs take precedence over fontproperties defaults."""
plt.figure()
text1 = plt.xlabel("value", fontproperties='Times New Roman', size=40.0)
text2 = plt.ylabel("counts", size=40.0, fontproperties='Times New Roman')
assert text1.get_size() == 40.0
assert text2.get_size() == 40.0
6 changes: 5 additions & 1 deletion lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ def __init__(self,

def update(self, kwargs):
# docstring inherited
# Update bbox last, as it depends on font properties.
sentinel = object() # bbox can be None, so use another sentinel.
# Update fontproperties first, as it has lowest priority.
fontproperties = kwargs.pop("fontproperties", sentinel)
if fontproperties is not sentinel:
self.set_fontproperties(fontproperties)
# Update bbox last, as it depends on font properties.
bbox = kwargs.pop("bbox", sentinel)
super().update(kwargs)
if bbox is not sentinel:
Expand Down