Skip to content

Commit 3e1eaf0

Browse files
committed
Fix setting Text's FontProperties behaviour
Co-authored-by: Robert Augustynowicz <[email protected]> Closes: matplotlib#16389 Previously, setting Text's FontProperties overwrites any old properties After the change, setting Text's FontProperties merges with old properties
1 parent dbc35a9 commit 3e1eaf0

7 files changed

Lines changed: 754 additions & 4 deletions

File tree

‎lib/matplotlib/font_manager.py‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ def __init__(self,
622622
fname = None, # if set, it's a hardcoded filename to use
623623
):
624624
self._family = _normalize_font_family(rcParams['font.family'])
625-
self._slant = rcParams['font.style']
625+
self._style = rcParams['font.style']
626626
self._variant = rcParams['font.variant']
627627
self._weight = rcParams['font.weight']
628628
self._stretch = rcParams['font.stretch']
@@ -692,7 +692,7 @@ def get_style(self):
692692
"""
693693
Return the font style. Values are: 'normal', 'italic' or 'oblique'.
694694
"""
695-
return self._slant
695+
return self._style
696696
get_slant = get_style
697697

698698
def get_variant(self):
@@ -763,7 +763,7 @@ def set_style(self, style):
763763
if style is None:
764764
style = rcParams['font.style']
765765
cbook._check_in_list(['normal', 'italic', 'oblique'], style=style)
766-
self._slant = style
766+
self._style = style
767767
set_slant = set_style
768768

769769
def set_variant(self, variant):
@@ -862,6 +862,27 @@ def copy(self):
862862
vars(new).update(vars(self))
863863
return new
864864

865+
def merge(self, fp):
866+
"""
867+
Merges all keys from fp into self whose value is not default.
868+
869+
Parameters
870+
----------
871+
fp : `.font_manager.FontProperties`
872+
873+
Returns
874+
-------
875+
`.font_manager.FontProperties`
876+
Self
877+
"""
878+
self_vars = vars(self)
879+
for k, v in vars(fp).items():
880+
# k starts with an underscore, remove it
881+
rcparam_k = 'font.' + k[1:]
882+
if rcparam_k in rcParams and rcParams[rcparam_k] != v:
883+
self_vars[k] = v
884+
return self
885+
865886

866887
class _JSONEncoder(json.JSONEncoder):
867888
def default(self, o):
Binary file not shown.
18.2 KB
Loading

0 commit comments

Comments
 (0)