44
44
from dummy_threading import Timer
45
45
46
46
import matplotlib as mpl
47
- from matplotlib import _api , _afm , cbook , ft2font , rcParams
47
+ from matplotlib import _api , _afm , cbook , ft2font
48
48
from matplotlib ._fontconfig_pattern import (
49
49
parse_fontconfig_pattern , generate_fontconfig_pattern )
50
50
from matplotlib .rcsetup import _validators
@@ -682,6 +682,7 @@ def __init__(self, family=None, style=None, variant=None, weight=None,
682
682
stretch = None , size = None ,
683
683
fname = None , # if set, it's a hardcoded filename to use
684
684
math_fontfamily = None ):
685
+ rcParams = mpl .rcParams
685
686
self ._family = _normalize_font_family (rcParams ['font.family' ])
686
687
self ._slant = rcParams ['font.style' ]
687
688
self ._variant = rcParams ['font.variant' ]
@@ -823,7 +824,7 @@ def set_family(self, family):
823
824
:rc:`text.usetex` is `True`.
824
825
"""
825
826
if family is None :
826
- family = rcParams ['font.family' ]
827
+ family = mpl . rcParams ['font.family' ]
827
828
self ._family = _normalize_font_family (family )
828
829
set_name = set_family
829
830
@@ -832,7 +833,7 @@ def set_style(self, style):
832
833
Set the font style. Values are: 'normal', 'italic' or 'oblique'.
833
834
"""
834
835
if style is None :
835
- style = rcParams ['font.style' ]
836
+ style = mpl . rcParams ['font.style' ]
836
837
_api .check_in_list (['normal' , 'italic' , 'oblique' ], style = style )
837
838
self ._slant = style
838
839
set_slant = set_style
@@ -842,7 +843,7 @@ def set_variant(self, variant):
842
843
Set the font variant. Values are: 'normal' or 'small-caps'.
843
844
"""
844
845
if variant is None :
845
- variant = rcParams ['font.variant' ]
846
+ variant = mpl . rcParams ['font.variant' ]
846
847
_api .check_in_list (['normal' , 'small-caps' ], variant = variant )
847
848
self ._variant = variant
848
849
@@ -854,7 +855,7 @@ def set_weight(self, weight):
854
855
'demi', 'bold', 'heavy', 'extra bold', 'black'
855
856
"""
856
857
if weight is None :
857
- weight = rcParams ['font.weight' ]
858
+ weight = mpl . rcParams ['font.weight' ]
858
859
try :
859
860
weight = int (weight )
860
861
if weight < 0 or weight > 1000 :
@@ -872,7 +873,7 @@ def set_stretch(self, stretch):
872
873
'ultra-expanded', or a numeric value in the range 0-1000.
873
874
"""
874
875
if stretch is None :
875
- stretch = rcParams ['font.stretch' ]
876
+ stretch = mpl . rcParams ['font.stretch' ]
876
877
try :
877
878
stretch = int (stretch )
878
879
if stretch < 0 or stretch > 1000 :
@@ -889,7 +890,7 @@ def set_size(self, size):
889
890
or an absolute font size, e.g., 12.
890
891
"""
891
892
if size is None :
892
- size = rcParams ['font.size' ]
893
+ size = mpl . rcParams ['font.size' ]
893
894
try :
894
895
size = float (size )
895
896
except ValueError :
@@ -955,7 +956,7 @@ def set_math_fontfamily(self, fontfamily):
955
956
.text.Text.get_math_fontfamily
956
957
"""
957
958
if fontfamily is None :
958
- fontfamily = rcParams ['mathtext.fontset' ]
959
+ fontfamily = mpl . rcParams ['mathtext.fontset' ]
959
960
else :
960
961
valid_fonts = _validators ['mathtext.fontset' ].valid .values ()
961
962
# _check_in_list() Validates the parameter math_fontfamily as
@@ -1133,7 +1134,7 @@ def get_default_size():
1133
1134
"""
1134
1135
Return the default font size.
1135
1136
"""
1136
- return rcParams ['font.size' ]
1137
+ return mpl . rcParams ['font.size' ]
1137
1138
1138
1139
def set_default_weight (self , weight ):
1139
1140
"""
@@ -1145,7 +1146,7 @@ def set_default_weight(self, weight):
1145
1146
def _expand_aliases (family ):
1146
1147
if family in ('sans' , 'sans serif' ):
1147
1148
family = 'sans-serif'
1148
- return rcParams ['font.' + family ]
1149
+ return mpl . rcParams ['font.' + family ]
1149
1150
1150
1151
# Each of the scoring functions below should return a value between
1151
1152
# 0.0 (perfect match) and 1.0 (terrible match)
@@ -1323,7 +1324,7 @@ def findfont(self, prop, fontext='ttf', directory=None,
1323
1324
# Pass the relevant rcParams (and the font manager, as `self`) to
1324
1325
# _findfont_cached so to prevent using a stale cache entry after an
1325
1326
# rcParam was changed.
1326
- rc_params = tuple (tuple (rcParams [key ]) for key in [
1327
+ rc_params = tuple (tuple (mpl . rcParams [key ]) for key in [
1327
1328
"font.serif" , "font.sans-serif" , "font.cursive" , "font.fantasy" ,
1328
1329
"font.monospace" ])
1329
1330
return self ._findfont_cached (
@@ -1446,10 +1447,10 @@ def get_font(filename, hinting_factor=None):
1446
1447
# single font is selected using two different relative paths.
1447
1448
filename = _cached_realpath (filename )
1448
1449
if hinting_factor is None :
1449
- hinting_factor = rcParams ['text.hinting_factor' ]
1450
+ hinting_factor = mpl . rcParams ['text.hinting_factor' ]
1450
1451
# also key on the thread ID to prevent segfaults with multi-threading
1451
1452
return _get_font (filename , hinting_factor ,
1452
- _kerning_factor = rcParams ['text.kerning_factor' ],
1453
+ _kerning_factor = mpl . rcParams ['text.kerning_factor' ],
1453
1454
thread_id = threading .get_ident ())
1454
1455
1455
1456
0 commit comments