Skip to content

Commit ae89d3e

Browse files
committed
MNT: ensure that defaults are cached init
This appears to already be the case for all of these properties, but remove the rcparams lookup from the get_* methods just to be sure.
1 parent 583748a commit ae89d3e

File tree

2 files changed

+12
-31
lines changed

2 files changed

+12
-31
lines changed

lib/matplotlib/font_manager.py

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -683,11 +683,11 @@ def __init__(self,
683683
_init = None # used only by copy()
684684
):
685685
self._family = None
686-
self._slant = None
687-
self._variant = None
688-
self._weight = None
689-
self._stretch = None
690-
self._size = None
686+
self._slant = rcParams['font.style']
687+
self._variant = rcParams['font.variant']
688+
self._weight = rcParams['font.weight']
689+
self._stretch = rcParams['font.stretch']
690+
self._size = rcParams['font.size']
691691
self._file = None
692692

693693
# This is used only by copy()
@@ -741,11 +741,6 @@ def get_family(self):
741741
"""
742742
Return a list of font names that comprise the font family.
743743
"""
744-
if self._family is None:
745-
family = rcParams['font.family']
746-
if is_string_like(family):
747-
return [family]
748-
return family
749744
return self._family
750745

751746
def get_name(self):
@@ -760,8 +755,6 @@ def get_style(self):
760755
Return the font style. Values are: 'normal', 'italic' or
761756
'oblique'.
762757
"""
763-
if self._slant is None:
764-
return rcParams['font.style']
765758
return self._slant
766759
get_slant = get_style
767760

@@ -770,8 +763,6 @@ def get_variant(self):
770763
Return the font variant. Values are: 'normal' or
771764
'small-caps'.
772765
"""
773-
if self._variant is None:
774-
return rcParams['font.variant']
775766
return self._variant
776767

777768
def get_weight(self):
@@ -781,8 +772,6 @@ def get_weight(self):
781772
'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold',
782773
'heavy', 'extra bold', 'black'
783774
"""
784-
if self._weight is None:
785-
return rcParams['font.weight']
786775
return self._weight
787776

788777
def get_stretch(self):
@@ -791,26 +780,16 @@ def get_stretch(self):
791780
'extra-condensed', 'condensed', 'semi-condensed', 'normal',
792781
'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'.
793782
"""
794-
if self._stretch is None:
795-
return rcParams['font.stretch']
796783
return self._stretch
797784

798785
def get_size(self):
799786
"""
800787
Return the font size.
801788
"""
802-
if self._size is None:
803-
return rcParams['font.size']
804789
return self._size
805790

806791
def get_size_in_points(self):
807-
if self._size is not None:
808-
try:
809-
return float(self._size)
810-
except ValueError:
811-
pass
812-
default_size = FontManager.get_default_size()
813-
return default_size * font_scalings.get(self._size)
792+
return self._size
814793

815794
def get_file(self):
816795
"""

lib/matplotlib/text.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def _get_layout(self, renderer):
355355

356356
baseline = 0
357357
for i, line in enumerate(lines):
358-
clean_line, ismath = self.is_math_text(line)
358+
clean_line, ismath = self.is_math_text(line, self.get_usetex())
359359
if clean_line:
360360
w, h, d = renderer.get_text_width_height_descent(clean_line,
361361
self._fontproperties,
@@ -782,7 +782,7 @@ def draw(self, renderer):
782782
y = y + posy
783783
if renderer.flipy():
784784
y = canvash - y
785-
clean_line, ismath = textobj.is_math_text(line)
785+
clean_line, ismath = textobj.is_math_text(line, self.get_usetex())
786786

787787
if textobj.get_path_effects():
788788
from matplotlib.patheffects import PathEffectRenderer
@@ -1212,7 +1212,7 @@ def set_text(self, s):
12121212
self.stale = True
12131213

12141214
@staticmethod
1215-
def is_math_text(s):
1215+
def is_math_text(s, usetex=None):
12161216
"""
12171217
Returns a cleaned string and a boolean flag.
12181218
The flag indicates if the given string *s* contains any mathtext,
@@ -1222,7 +1222,9 @@ def is_math_text(s):
12221222
"""
12231223
# Did we find an even number of non-escaped dollar signs?
12241224
# If so, treat is as math text.
1225-
if self.get_usetex():
1225+
if usetex is None:
1226+
usetex = rcParams['text.usetex']
1227+
if usetex:
12261228
if s == ' ':
12271229
s = r'\ '
12281230
return s, 'TeX'

0 commit comments

Comments
 (0)