Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b512c70

Browse files
committed
FIX: ensure that used sub-packages are actually imported
closes #22305
1 parent fd51e05 commit b512c70

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

lib/matplotlib/font_manager.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from dummy_threading import Timer
4545

4646
import matplotlib as mpl
47-
from matplotlib import _api, _afm, cbook, ft2font, rcParams
47+
from matplotlib import _api, _afm, cbook, ft2font
4848
from matplotlib._fontconfig_pattern import (
4949
parse_fontconfig_pattern, generate_fontconfig_pattern)
5050
from matplotlib.rcsetup import _validators
@@ -682,6 +682,7 @@ def __init__(self, family=None, style=None, variant=None, weight=None,
682682
stretch=None, size=None,
683683
fname=None, # if set, it's a hardcoded filename to use
684684
math_fontfamily=None):
685+
rcParams = mpl.rcParams
685686
self._family = _normalize_font_family(rcParams['font.family'])
686687
self._slant = rcParams['font.style']
687688
self._variant = rcParams['font.variant']
@@ -823,7 +824,7 @@ def set_family(self, family):
823824
:rc:`text.usetex` is `True`.
824825
"""
825826
if family is None:
826-
family = rcParams['font.family']
827+
family = mpl.rcParams['font.family']
827828
self._family = _normalize_font_family(family)
828829
set_name = set_family
829830

@@ -832,7 +833,7 @@ def set_style(self, style):
832833
Set the font style. Values are: 'normal', 'italic' or 'oblique'.
833834
"""
834835
if style is None:
835-
style = rcParams['font.style']
836+
style = mpl.rcParams['font.style']
836837
_api.check_in_list(['normal', 'italic', 'oblique'], style=style)
837838
self._slant = style
838839
set_slant = set_style
@@ -842,7 +843,7 @@ def set_variant(self, variant):
842843
Set the font variant. Values are: 'normal' or 'small-caps'.
843844
"""
844845
if variant is None:
845-
variant = rcParams['font.variant']
846+
variant = mpl.rcParams['font.variant']
846847
_api.check_in_list(['normal', 'small-caps'], variant=variant)
847848
self._variant = variant
848849

@@ -854,7 +855,7 @@ def set_weight(self, weight):
854855
'demi', 'bold', 'heavy', 'extra bold', 'black'
855856
"""
856857
if weight is None:
857-
weight = rcParams['font.weight']
858+
weight = mpl.rcParams['font.weight']
858859
try:
859860
weight = int(weight)
860861
if weight < 0 or weight > 1000:
@@ -872,7 +873,7 @@ def set_stretch(self, stretch):
872873
'ultra-expanded', or a numeric value in the range 0-1000.
873874
"""
874875
if stretch is None:
875-
stretch = rcParams['font.stretch']
876+
stretch = mpl.rcParams['font.stretch']
876877
try:
877878
stretch = int(stretch)
878879
if stretch < 0 or stretch > 1000:
@@ -889,7 +890,7 @@ def set_size(self, size):
889890
or an absolute font size, e.g., 12.
890891
"""
891892
if size is None:
892-
size = rcParams['font.size']
893+
size = mpl.rcParams['font.size']
893894
try:
894895
size = float(size)
895896
except ValueError:
@@ -955,7 +956,7 @@ def set_math_fontfamily(self, fontfamily):
955956
.text.Text.get_math_fontfamily
956957
"""
957958
if fontfamily is None:
958-
fontfamily = rcParams['mathtext.fontset']
959+
fontfamily = mpl.rcParams['mathtext.fontset']
959960
else:
960961
valid_fonts = _validators['mathtext.fontset'].valid.values()
961962
# _check_in_list() Validates the parameter math_fontfamily as
@@ -1133,7 +1134,7 @@ def get_default_size():
11331134
"""
11341135
Return the default font size.
11351136
"""
1136-
return rcParams['font.size']
1137+
return mpl.rcParams['font.size']
11371138

11381139
def set_default_weight(self, weight):
11391140
"""
@@ -1145,7 +1146,7 @@ def set_default_weight(self, weight):
11451146
def _expand_aliases(family):
11461147
if family in ('sans', 'sans serif'):
11471148
family = 'sans-serif'
1148-
return rcParams['font.' + family]
1149+
return mpl.rcParams['font.' + family]
11491150

11501151
# Each of the scoring functions below should return a value between
11511152
# 0.0 (perfect match) and 1.0 (terrible match)
@@ -1323,7 +1324,7 @@ def findfont(self, prop, fontext='ttf', directory=None,
13231324
# Pass the relevant rcParams (and the font manager, as `self`) to
13241325
# _findfont_cached so to prevent using a stale cache entry after an
13251326
# rcParam was changed.
1326-
rc_params = tuple(tuple(rcParams[key]) for key in [
1327+
rc_params = tuple(tuple(mpl.rcParams[key]) for key in [
13271328
"font.serif", "font.sans-serif", "font.cursive", "font.fantasy",
13281329
"font.monospace"])
13291330
return self._findfont_cached(
@@ -1446,10 +1447,10 @@ def get_font(filename, hinting_factor=None):
14461447
# single font is selected using two different relative paths.
14471448
filename = _cached_realpath(filename)
14481449
if hinting_factor is None:
1449-
hinting_factor = rcParams['text.hinting_factor']
1450+
hinting_factor = mpl.rcParams['text.hinting_factor']
14501451
# also key on the thread ID to prevent segfaults with multi-threading
14511452
return _get_font(filename, hinting_factor,
1452-
_kerning_factor=rcParams['text.kerning_factor'],
1453+
_kerning_factor=mpl.rcParams['text.kerning_factor'],
14531454
thread_id=threading.get_ident())
14541455

14551456

lib/matplotlib/ticker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
import matplotlib as mpl
135135
from matplotlib import _api, cbook
136136
from matplotlib import transforms as mtransforms
137+
import matplotlib.font_manager as mfont_manager
137138

138139
_log = logging.getLogger(__name__)
139140

@@ -441,8 +442,8 @@ def __init__(self, useOffset=None, useMathText=None, useLocale=None):
441442
useMathText = mpl.rcParams['axes.formatter.use_mathtext']
442443
if useMathText is False:
443444
try:
444-
ufont = mpl.font_manager.findfont(
445-
mpl.font_manager.FontProperties(
445+
ufont = mfont_manager.findfont(
446+
mfont_manager.FontProperties(
446447
mpl.rcParams["font.family"]
447448
),
448449
fallback_to_default=False,

0 commit comments

Comments
 (0)