Skip to content

Commit bb37ab6

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 98e9fb2 commit bb37ab6

File tree

2 files changed

+12
-31
lines changed

2 files changed

+12
-31
lines changed

lib/matplotlib/font_manager.py

+6-27
Original file line numberDiff line numberDiff line change
@@ -682,11 +682,11 @@ def __init__(self,
682682
_init = None # used only by copy()
683683
):
684684
self._family = None
685-
self._slant = None
686-
self._variant = None
687-
self._weight = None
688-
self._stretch = None
689-
self._size = None
685+
self._slant = rcParams['font.style']
686+
self._variant = rcParams['font.variant']
687+
self._weight = rcParams['font.weight']
688+
self._stretch = rcParams['font.stretch']
689+
self._size = rcParams['font.size']
690690
self._file = None
691691

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

750745
def get_name(self):
@@ -759,8 +754,6 @@ def get_style(self):
759754
Return the font style. Values are: 'normal', 'italic' or
760755
'oblique'.
761756
"""
762-
if self._slant is None:
763-
return rcParams['font.style']
764757
return self._slant
765758
get_slant = get_style
766759

@@ -769,8 +762,6 @@ def get_variant(self):
769762
Return the font variant. Values are: 'normal' or
770763
'small-caps'.
771764
"""
772-
if self._variant is None:
773-
return rcParams['font.variant']
774765
return self._variant
775766

776767
def get_weight(self):
@@ -780,8 +771,6 @@ def get_weight(self):
780771
'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold',
781772
'heavy', 'extra bold', 'black'
782773
"""
783-
if self._weight is None:
784-
return rcParams['font.weight']
785774
return self._weight
786775

787776
def get_stretch(self):
@@ -790,26 +779,16 @@ def get_stretch(self):
790779
'extra-condensed', 'condensed', 'semi-condensed', 'normal',
791780
'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'.
792781
"""
793-
if self._stretch is None:
794-
return rcParams['font.stretch']
795782
return self._stretch
796783

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

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

814793
def get_file(self):
815794
"""

lib/matplotlib/text.py

+6-4
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)