diff --git a/lib/matplotlib/tests/test_text.py b/lib/matplotlib/tests/test_text.py index c4263dde9178..a8ed808d4f31 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -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 diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 78fb5c57f7e2..2a8a708e7c18 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -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: