Skip to content
Open
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
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7543,6 +7543,18 @@ def test_title_location_roundtrip():
ax.set_title('fail', loc='foo')


@pytest.mark.parametrize("kwargs", [
{"font": "DejaVu Sans", "fontsize": 20},
{"fontsize": 20, "font": "DejaVu Sans"},
{"font": mfont_manager.FontProperties(family="DejaVu Sans"), "fontsize": 20},
{"fontsize": 20, "font": mfont_manager.FontProperties(family="DejaVu Sans")},
])
def test_title_fontproperties_kwarg_precedence(kwargs):
fig, ax = plt.subplots()
title = ax.set_title("Title", **kwargs)
assert title.get_fontsize() == 20


@pytest.mark.parametrize('sharex', [True, False])
def test_title_location_shared(sharex):
fig, axs = plt.subplots(2, 1, sharex=sharex)
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,18 @@ def test_fontproperties_kwarg_precedence():
assert text2.get_size() == 40.0


@pytest.mark.parametrize("kwargs", [
{"font": "DejaVu Sans", "fontsize": 20},
{"fontsize": 20, "font": "DejaVu Sans"},
{"font_properties": FontProperties(family="DejaVu Sans"), "fontsize": 20},
{"fontsize": 20, "fontproperties": FontProperties(family="DejaVu Sans")},
])
def test_internal_update_fontproperties_kwarg_precedence(kwargs):
text = Text()
text._internal_update(kwargs)
assert text.get_fontsize() == 20


def test_transform_rotates_text():
ax = plt.gca()
transform = mtransforms.Affine2D().rotate_deg(30)
Expand Down
10 changes: 10 additions & 0 deletions lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,16 @@ def update(self, kwargs):
ret.append(self.set_bbox(bbox))
return ret

def _internal_update(self, kwargs):
# Apply complete font properties first, as they have lowest priority.
kwargs = kwargs.copy()
fontproperties = {
key: kwargs.pop(key) for key in list(kwargs)
if key in {"font", "font_properties", "fontproperties"}}
ret = super()._internal_update(fontproperties)
ret.extend(super()._internal_update(kwargs))
return ret

def __getstate__(self):
d = super().__getstate__()
# remove the cached _renderer (if it exists)
Expand Down
Loading