Skip to content

Commit 24c9cb9

Browse files
committed
Get rcParams from mpl
1 parent a0f16a8 commit 24c9cb9

File tree

9 files changed

+60
-56
lines changed

9 files changed

+60
-56
lines changed

lib/matplotlib/_layoutgrid.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import kiwisolver as kiwi
2121
import logging
2222
import numpy as np
23+
24+
import matplotlib as mpl
25+
import matplotlib.patches as mpatches
2326
from matplotlib.transforms import Bbox
2427

2528
_log = logging.getLogger(__name__)
@@ -509,13 +512,10 @@ def seq_id():
509512

510513
def plot_children(fig, lg=None, level=0):
511514
"""Simple plotting to show where boxes are."""
512-
import matplotlib.pyplot as plt
513-
import matplotlib.patches as mpatches
514-
515515
if lg is None:
516516
_layoutgrids = fig.get_layout_engine().execute(fig)
517517
lg = _layoutgrids[fig]
518-
colors = plt.rcParams["axes.prop_cycle"].by_key()["color"]
518+
colors = mpl.rcParams["axes.prop_cycle"].by_key()["color"]
519519
col = colors[level]
520520
for i in range(lg.nrows):
521521
for j in range(lg.ncols):

lib/matplotlib/colors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ def to_rgba(c, alpha=None):
288288
"""
289289
# Special-case nth color syntax because it should not be cached.
290290
if _is_nth_color(c):
291-
from matplotlib import rcParams
292-
prop_cycler = rcParams['axes.prop_cycle']
291+
prop_cycler = mpl.rcParams['axes.prop_cycle']
293292
colors = prop_cycler.by_key().get('color', ['k'])
294293
c = colors[int(c[1:]) % len(colors)]
295294
try:

lib/matplotlib/font_manager.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import threading
4040

4141
import matplotlib as mpl
42-
from matplotlib import _api, _afm, cbook, ft2font, rcParams
42+
from matplotlib import _api, _afm, cbook, ft2font
4343
from matplotlib._fontconfig_pattern import (
4444
parse_fontconfig_pattern, generate_fontconfig_pattern)
4545
from matplotlib.rcsetup import _validators
@@ -810,7 +810,7 @@ def set_family(self, family):
810810
:rc:`text.usetex` is `True`. Default: :rc:`font.family`
811811
"""
812812
if family is None:
813-
family = rcParams['font.family']
813+
family = mpl.rcParams['font.family']
814814
if isinstance(family, str):
815815
family = [family]
816816
self._family = family
@@ -824,7 +824,7 @@ def set_style(self, style):
824824
style : {'normal', 'italic', 'oblique'}, default: :rc:`font.style`
825825
"""
826826
if style is None:
827-
style = rcParams['font.style']
827+
style = mpl.rcParams['font.style']
828828
_api.check_in_list(['normal', 'italic', 'oblique'], style=style)
829829
self._slant = style
830830

@@ -837,7 +837,7 @@ def set_variant(self, variant):
837837
variant : {'normal', 'small-caps'}, default: :rc:`font.variant`
838838
"""
839839
if variant is None:
840-
variant = rcParams['font.variant']
840+
variant = mpl.rcParams['font.variant']
841841
_api.check_in_list(['normal', 'small-caps'], variant=variant)
842842
self._variant = variant
843843

@@ -853,7 +853,7 @@ def set_weight(self, weight):
853853
If int, must be in the range 0-1000.
854854
"""
855855
if weight is None:
856-
weight = rcParams['font.weight']
856+
weight = mpl.rcParams['font.weight']
857857
if weight in weight_dict:
858858
self._weight = weight
859859
return
@@ -879,7 +879,7 @@ def set_stretch(self, stretch):
879879
If int, must be in the range 0-1000.
880880
"""
881881
if stretch is None:
882-
stretch = rcParams['font.stretch']
882+
stretch = mpl.rcParams['font.stretch']
883883
if stretch in stretch_dict:
884884
self._stretch = stretch
885885
return
@@ -905,7 +905,7 @@ def set_size(self, size):
905905
relative to the default font size.
906906
"""
907907
if size is None:
908-
size = rcParams['font.size']
908+
size = mpl.rcParams['font.size']
909909
try:
910910
size = float(size)
911911
except ValueError:
@@ -971,7 +971,7 @@ def set_math_fontfamily(self, fontfamily):
971971
.text.Text.get_math_fontfamily
972972
"""
973973
if fontfamily is None:
974-
fontfamily = rcParams['mathtext.fontset']
974+
fontfamily = mpl.rcParams['mathtext.fontset']
975975
else:
976976
valid_fonts = _validators['mathtext.fontset'].valid.values()
977977
# _check_in_list() Validates the parameter math_fontfamily as
@@ -1152,7 +1152,7 @@ def get_default_size():
11521152
"""
11531153
Return the default font size.
11541154
"""
1155-
return rcParams['font.size']
1155+
return mpl.rcParams['font.size']
11561156

11571157
def set_default_weight(self, weight):
11581158
"""
@@ -1164,7 +1164,7 @@ def set_default_weight(self, weight):
11641164
def _expand_aliases(family):
11651165
if family in ('sans', 'sans serif'):
11661166
family = 'sans-serif'
1167-
return rcParams['font.' + family]
1167+
return mpl.rcParams['font.' + family]
11681168

11691169
# Each of the scoring functions below should return a value between
11701170
# 0.0 (perfect match) and 1.0 (terrible match)
@@ -1342,7 +1342,7 @@ def findfont(self, prop, fontext='ttf', directory=None,
13421342
# Pass the relevant rcParams (and the font manager, as `self`) to
13431343
# _findfont_cached so to prevent using a stale cache entry after an
13441344
# rcParam was changed.
1345-
rc_params = tuple(tuple(rcParams[key]) for key in [
1345+
rc_params = tuple(tuple(mpl.rcParams[key]) for key in [
13461346
"font.serif", "font.sans-serif", "font.cursive", "font.fantasy",
13471347
"font.monospace"])
13481348
return self._findfont_cached(
@@ -1595,13 +1595,13 @@ def get_font(font_filepaths, hinting_factor=None):
15951595
paths = tuple(_cached_realpath(fname) for fname in font_filepaths)
15961596

15971597
if hinting_factor is None:
1598-
hinting_factor = rcParams['text.hinting_factor']
1598+
hinting_factor = mpl.rcParams['text.hinting_factor']
15991599

16001600
return _get_font(
16011601
# must be a tuple to be cached
16021602
paths,
16031603
hinting_factor,
1604-
_kerning_factor=rcParams['text.kerning_factor'],
1604+
_kerning_factor=mpl.rcParams['text.kerning_factor'],
16051605
# also key on the thread ID to prevent segfaults with multi-threading
16061606
thread_id=threading.get_ident()
16071607
)

lib/matplotlib/gridspec.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import numpy as np
1919

2020
import matplotlib as mpl
21-
from matplotlib import _api, _pylab_helpers, _tight_layout, rcParams
21+
from matplotlib import _api, _pylab_helpers, _tight_layout
2222
from matplotlib.transforms import Bbox
2323

2424
_log = logging.getLogger(__name__)
@@ -430,7 +430,8 @@ def get_subplot_params(self, figure=None):
430430
- :rc:`figure.subplot.*`
431431
"""
432432
if figure is None:
433-
kw = {k: rcParams["figure.subplot."+k] for k in self._AllowedKeys}
433+
kw = {k: mpl.rcParams["figure.subplot."+k]
434+
for k in self._AllowedKeys}
434435
subplotpars = mpl.figure.SubplotParams(**kw)
435436
else:
436437
subplotpars = copy.copy(figure.subplotpars)
@@ -520,10 +521,10 @@ def get_subplot_params(self, figure=None):
520521
"""Return a dictionary of subplot layout parameters."""
521522
hspace = (self._hspace if self._hspace is not None
522523
else figure.subplotpars.hspace if figure is not None
523-
else rcParams["figure.subplot.hspace"])
524+
else mpl.rcParams["figure.subplot.hspace"])
524525
wspace = (self._wspace if self._wspace is not None
525526
else figure.subplotpars.wspace if figure is not None
526-
else rcParams["figure.subplot.wspace"])
527+
else mpl.rcParams["figure.subplot.wspace"])
527528

528529
figbox = self._subplot_spec.get_position(figure)
529530
left, bottom, right, top = figbox.extents

lib/matplotlib/markers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@
139139

140140
import numpy as np
141141

142-
from . import _api, cbook, rcParams
142+
import matplotlib as mpl
143+
from . import _api, cbook
143144
from .path import Path
144145
from .transforms import IdentityTransform, Affine2D
145146
from ._enums import JoinStyle, CapStyle
@@ -309,7 +310,7 @@ def _set_fillstyle(self, fillstyle):
309310
markerfacecolor.
310311
"""
311312
if fillstyle is None:
312-
fillstyle = rcParams['markers.fillstyle']
313+
fillstyle = mpl.rcParams['markers.fillstyle']
313314
_api.check_in_list(self.fillstyles, fillstyle=fillstyle)
314315
self._fillstyle = fillstyle
315316
self._recache()
@@ -524,7 +525,7 @@ def _set_mathtext_path(self):
524525
# again, the properties could be initialised just once outside
525526
# this function
526527
text = TextPath(xy=(0, 0), s=self.get_marker(),
527-
usetex=rcParams['text.usetex'])
528+
usetex=mpl.rcParams['text.usetex'])
528529
if len(text.vertices) == 0:
529530
return
530531

lib/matplotlib/spines.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import numpy as np
55

6-
import matplotlib
7-
from matplotlib import _api, _docstring, rcParams
6+
import matplotlib as mpl
7+
from matplotlib import _api, _docstring
88
from matplotlib.artist import allow_rasterization
99
import matplotlib.transforms as mtransforms
1010
import matplotlib.patches as mpatches
@@ -56,8 +56,8 @@ def __init__(self, axes, spine_type, path, **kwargs):
5656
self.set_figure(self.axes.figure)
5757
self.spine_type = spine_type
5858
self.set_facecolor('none')
59-
self.set_edgecolor(rcParams['axes.edgecolor'])
60-
self.set_linewidth(rcParams['axes.linewidth'])
59+
self.set_edgecolor(mpl.rcParams['axes.edgecolor'])
60+
self.set_linewidth(mpl.rcParams['axes.linewidth'])
6161
self.set_capstyle('projecting')
6262
self.axis = None
6363

@@ -70,7 +70,7 @@ def __init__(self, axes, spine_type, path, **kwargs):
7070
# non-rectangular axes is currently implemented, and this lets
7171
# them pass through the spines machinery without errors.)
7272
self._position = None
73-
_api.check_isinstance(matplotlib.path.Path, path=path)
73+
_api.check_isinstance(mpath.Path, path=path)
7474
self._path = path
7575

7676
# To support drawing both linear and circular spines, this
@@ -432,7 +432,7 @@ def linear_spine(cls, axes, spine_type, **kwargs):
432432
else:
433433
raise ValueError('unable to make path for spine "%s"' % spine_type)
434434
result = cls(axes, spine_type, path, **kwargs)
435-
result.set_visible(rcParams['axes.spines.{0}'.format(spine_type)])
435+
result.set_visible(mpl.rcParams['axes.spines.{0}'.format(spine_type)])
436436

437437
return result
438438

lib/matplotlib/streamplot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import numpy as np
77

8-
import matplotlib
8+
import matplotlib as mpl
99
from matplotlib import _api, cm, patches
1010
import matplotlib.colors as mcolors
1111
import matplotlib.collections as mcollections
@@ -103,7 +103,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
103103
color = axes._get_lines.get_next_color()
104104

105105
if linewidth is None:
106-
linewidth = matplotlib.rcParams['lines.linewidth']
106+
linewidth = mpl.rcParams['lines.linewidth']
107107

108108
line_kw = {}
109109
arrow_kw = dict(arrowstyle=arrowstyle, mutation_scale=10 * arrowsize)
@@ -231,7 +231,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
231231
lc.set_norm(norm)
232232
axes.add_collection(lc)
233233

234-
ac = matplotlib.collections.PatchCollection(arrows)
234+
ac = mcollections.PatchCollection(arrows)
235235
# Adding the collection itself is broken; see #2341.
236236
for p in arrows:
237237
axes.add_patch(p)

lib/mpl_toolkits/axisartist/axis_artist.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575

7676
import numpy as np
7777

78-
from matplotlib import _api, cbook, rcParams
78+
import matplotlib as mpl
79+
from matplotlib import _api, cbook
7980
import matplotlib.artist as martist
8081
import matplotlib.colors as mcolors
8182
import matplotlib.text as mtext
@@ -781,11 +782,11 @@ def _init_line(self):
781782
if axisline_style is None:
782783
self.line = PathPatch(
783784
self._axis_artist_helper.get_line(self.axes),
784-
color=rcParams['axes.edgecolor'],
785+
color=mpl.rcParams['axes.edgecolor'],
785786
fill=False,
786-
linewidth=rcParams['axes.linewidth'],
787-
capstyle=rcParams['lines.solid_capstyle'],
788-
joinstyle=rcParams['lines.solid_joinstyle'],
787+
linewidth=mpl.rcParams['axes.linewidth'],
788+
capstyle=mpl.rcParams['lines.solid_capstyle'],
789+
joinstyle=mpl.rcParams['lines.solid_joinstyle'],
789790
transform=tran)
790791
else:
791792
self.line = axisline_style(self, transform=tran)
@@ -804,22 +805,24 @@ def _init_ticks(self, **kwargs):
804805

805806
self.major_ticks = Ticks(
806807
kwargs.get(
807-
"major_tick_size", rcParams[f"{axis_name}tick.major.size"]),
808+
"major_tick_size",
809+
mpl.rcParams[f"{axis_name}tick.major.size"]),
808810
axis=self.axis, transform=trans)
809811
self.minor_ticks = Ticks(
810812
kwargs.get(
811-
"minor_tick_size", rcParams[f"{axis_name}tick.minor.size"]),
813+
"minor_tick_size",
814+
mpl.rcParams[f"{axis_name}tick.minor.size"]),
812815
axis=self.axis, transform=trans)
813816

814-
size = rcParams[f"{axis_name}tick.labelsize"]
817+
size = mpl.rcParams[f"{axis_name}tick.labelsize"]
815818
self.major_ticklabels = TickLabels(
816819
axis=self.axis,
817820
axis_direction=self._axis_direction,
818821
figure=self.axes.figure,
819822
transform=trans,
820823
fontsize=size,
821824
pad=kwargs.get(
822-
"major_tick_pad", rcParams[f"{axis_name}tick.major.pad"]),
825+
"major_tick_pad", mpl.rcParams[f"{axis_name}tick.major.pad"]),
823826
)
824827
self.minor_ticklabels = TickLabels(
825828
axis=self.axis,
@@ -828,7 +831,7 @@ def _init_ticks(self, **kwargs):
828831
transform=trans,
829832
fontsize=size,
830833
pad=kwargs.get(
831-
"minor_tick_pad", rcParams[f"{axis_name}tick.minor.pad"]),
834+
"minor_tick_pad", mpl.rcParams[f"{axis_name}tick.minor.pad"]),
832835
)
833836

834837
def _get_tick_info(self, tick_iter):
@@ -903,7 +906,7 @@ def _init_offsetText(self, direction):
903906
"",
904907
xy=(x, y), xycoords="axes fraction",
905908
xytext=(0, 0), textcoords="offset points",
906-
color=rcParams['xtick.color'],
909+
color=mpl.rcParams['xtick.color'],
907910
horizontalalignment=ha, verticalalignment=va,
908911
)
909912
self.offsetText.set_transform(IdentityTransform())
@@ -927,8 +930,8 @@ def _init_label(self, **kwargs):
927930
self.label = AxisLabel(
928931
0, 0, "__from_axes__",
929932
color="auto",
930-
fontsize=kwargs.get("labelsize", rcParams['axes.labelsize']),
931-
fontweight=rcParams['axes.labelweight'],
933+
fontsize=kwargs.get("labelsize", mpl.rcParams['axes.labelsize']),
934+
fontweight=mpl.rcParams['axes.labelweight'],
932935
axis=self.axis,
933936
transform=tr,
934937
axis_direction=self._axis_direction,

lib/mpl_toolkits/axisartist/axislines.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import numpy as np
4343

4444
import matplotlib as mpl
45-
from matplotlib import _api, rcParams
45+
from matplotlib import _api
4646
import matplotlib.axes as maxes
4747
from matplotlib.path import Path
4848
from mpl_toolkits.axes_grid1 import mpl_axes
@@ -341,10 +341,10 @@ def new_gridlines(self, ax):
341341
*axis* : "both", "x" or "y"
342342
343343
"""
344-
gridlines = GridlinesCollection(None, transform=ax.transData,
345-
colors=rcParams['grid.color'],
346-
linestyles=rcParams['grid.linestyle'],
347-
linewidths=rcParams['grid.linewidth'])
344+
gridlines = GridlinesCollection(
345+
None, transform=ax.transData, colors=mpl.rcParams['grid.color'],
346+
linestyles=mpl.rcParams['grid.linestyle'],
347+
linewidths=mpl.rcParams['grid.linewidth'])
348348
ax._set_artist_props(gridlines)
349349
gridlines.set_grid_helper(self)
350350

@@ -488,9 +488,9 @@ def clear(self):
488488
# Init gridlines before clear() as clear() calls grid().
489489
self.gridlines = gridlines = GridlinesCollection(
490490
None, transform=self.transData,
491-
colors=rcParams['grid.color'],
492-
linestyles=rcParams['grid.linestyle'],
493-
linewidths=rcParams['grid.linewidth'])
491+
colors=mpl.rcParams['grid.color'],
492+
linestyles=mpl.rcParams['grid.linestyle'],
493+
linewidths=mpl.rcParams['grid.linewidth'])
494494
self._set_artist_props(gridlines)
495495
gridlines.set_grid_helper(self.get_grid_helper())
496496

0 commit comments

Comments
 (0)