Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ba7b86f

Browse filesBrowse files
authored
Merge pull request #23678 from oscargus/rcparamsimport
Get rcParams from mpl
2 parents 52e6a12 + 438d30b commit ba7b86f
Copy full SHA for ba7b86f

File tree

Expand file treeCollapse file tree

21 files changed

+163
-148
lines changed
Filter options
Expand file treeCollapse file tree

21 files changed

+163
-148
lines changed

‎examples/text_labels_and_annotations/custom_legends.py

Copy file name to clipboardExpand all lines: examples/text_labels_and_annotations/custom_legends.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
and call ``ax.legend()``, you will get the following:
2020
"""
2121
# sphinx_gallery_thumbnail_number = 2
22-
from matplotlib import rcParams, cycler
22+
import matplotlib as mpl
23+
from matplotlib import cycler
2324
import matplotlib.pyplot as plt
2425
import numpy as np
2526

@@ -29,7 +30,7 @@
2930
N = 10
3031
data = (np.geomspace(1, 10, 100) + np.random.randn(N, 100)).T
3132
cmap = plt.cm.coolwarm
32-
rcParams['axes.prop_cycle'] = cycler(color=cmap(np.linspace(0, 1, N)))
33+
mpl.rcParams['axes.prop_cycle'] = cycler(color=cmap(np.linspace(0, 1, N)))
3334

3435
fig, ax = plt.subplots()
3536
lines = ax.plot(data)

‎lib/matplotlib/_layoutgrid.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_layoutgrid.py
+4-4Lines 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/_tight_layout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_tight_layout.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
import numpy as np
1313

14-
from matplotlib import _api, artist as martist, rcParams
14+
import matplotlib as mpl
15+
from matplotlib import _api, artist as martist
1516
from matplotlib.font_manager import FontProperties
1617
from matplotlib.transforms import Bbox
1718

@@ -46,8 +47,8 @@ def _auto_adjust_subplotpars(
4647
"""
4748
rows, cols = shape
4849

49-
font_size_inch = (
50-
FontProperties(size=rcParams["font.size"]).get_size_in_points() / 72)
50+
font_size_inch = (FontProperties(
51+
size=mpl.rcParams["font.size"]).get_size_in_points() / 72)
5152
pad_inch = pad * font_size_inch
5253
vpad_inch = h_pad * font_size_inch if h_pad is not None else pad_inch
5354
hpad_inch = w_pad * font_size_inch if w_pad is not None else pad_inch

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+47-45Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy as np
88
from numpy import ma
99

10+
import matplotlib as mpl
1011
import matplotlib.category # Register category unit converter as side-effect.
1112
import matplotlib.cbook as cbook
1213
import matplotlib.collections as mcoll
@@ -29,7 +30,7 @@
2930
import matplotlib.transforms as mtransforms
3031
import matplotlib.tri as mtri
3132
import matplotlib.units as munits
32-
from matplotlib import _api, _docstring, _preprocess_data, rcParams
33+
from matplotlib import _api, _docstring, _preprocess_data
3334
from matplotlib.axes._base import (
3435
_AxesBase, _TransformedBoundsLocator, _process_plot_format)
3536
from matplotlib.axes._secondary_axes import SecondaryAxis
@@ -136,10 +137,10 @@ def set_title(self, label, fontdict=None, loc=None, pad=None, *, y=None,
136137
of valid text properties.
137138
"""
138139
if loc is None:
139-
loc = rcParams['axes.titlelocation']
140+
loc = mpl.rcParams['axes.titlelocation']
140141

141142
if y is None:
142-
y = rcParams['axes.titley']
143+
y = mpl.rcParams['axes.titley']
143144
if y is None:
144145
y = 1.0
145146
else:
@@ -151,15 +152,15 @@ def set_title(self, label, fontdict=None, loc=None, pad=None, *, y=None,
151152
'right': self._right_title}
152153
title = _api.check_getitem(titles, loc=loc.lower())
153154
default = {
154-
'fontsize': rcParams['axes.titlesize'],
155-
'fontweight': rcParams['axes.titleweight'],
155+
'fontsize': mpl.rcParams['axes.titlesize'],
156+
'fontweight': mpl.rcParams['axes.titleweight'],
156157
'verticalalignment': 'baseline',
157158
'horizontalalignment': loc.lower()}
158-
titlecolor = rcParams['axes.titlecolor']
159+
titlecolor = mpl.rcParams['axes.titlecolor']
159160
if not cbook._str_lower_equal(titlecolor, 'auto'):
160161
default["color"] = titlecolor
161162
if pad is None:
162-
pad = rcParams['axes.titlepad']
163+
pad = mpl.rcParams['axes.titlepad']
163164
self._set_title_offset_trans(float(pad))
164165
title.set_text(label)
165166
title.update(default)
@@ -2332,7 +2333,7 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
23322333
ezorder += 0.01
23332334
error_kw.setdefault('zorder', ezorder)
23342335
ecolor = kwargs.pop('ecolor', 'k')
2335-
capsize = kwargs.pop('capsize', rcParams["errorbar.capsize"])
2336+
capsize = kwargs.pop('capsize', mpl.rcParams["errorbar.capsize"])
23362337
error_kw.setdefault('ecolor', ecolor)
23372338
error_kw.setdefault('capsize', capsize)
23382339

@@ -2969,13 +2970,14 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
29692970
# resolve baseline format
29702971
if basefmt is None:
29712972
basefmt = (args[2] if len(args) > 2 else
2972-
"C2-" if rcParams["_internal.classic_mode"] else "C3-")
2973+
"C2-" if mpl.rcParams["_internal.classic_mode"] else
2974+
"C3-")
29732975
basestyle, basemarker, basecolor = _process_plot_format(basefmt)
29742976

29752977
# New behaviour in 3.1 is to use a LineCollection for the stemlines
29762978
if use_line_collection:
29772979
if linestyle is None:
2978-
linestyle = rcParams['lines.linestyle']
2980+
linestyle = mpl.rcParams['lines.linestyle']
29792981
xlines = self.vlines if orientation == "vertical" else self.hlines
29802982
stemlines = xlines(
29812983
locs, bottom, heads,
@@ -3209,7 +3211,7 @@ def get_next_color():
32093211
horizontalalignment=label_alignment_h,
32103212
verticalalignment=label_alignment_v,
32113213
rotation=label_rotation,
3212-
size=rcParams['xtick.labelsize'])
3214+
size=mpl.rcParams['xtick.labelsize'])
32133215
t.set(**textprops)
32143216
texts.append(t)
32153217

@@ -3528,7 +3530,7 @@ def _upcast_err(err):
35283530
# Make the style dict for caps (the "hats").
35293531
eb_cap_style = {**base_style, 'linestyle': 'none'}
35303532
if capsize is None:
3531-
capsize = rcParams["errorbar.capsize"]
3533+
capsize = mpl.rcParams["errorbar.capsize"]
35323534
if capsize > 0:
35333535
eb_cap_style['markersize'] = 2. * capsize
35343536
if capthick is not None:
@@ -3821,28 +3823,28 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
38213823

38223824
# Missing arguments default to rcParams.
38233825
if whis is None:
3824-
whis = rcParams['boxplot.whiskers']
3826+
whis = mpl.rcParams['boxplot.whiskers']
38253827
if bootstrap is None:
3826-
bootstrap = rcParams['boxplot.bootstrap']
3828+
bootstrap = mpl.rcParams['boxplot.bootstrap']
38273829

38283830
bxpstats = cbook.boxplot_stats(x, whis=whis, bootstrap=bootstrap,
38293831
labels=labels, autorange=autorange)
38303832
if notch is None:
3831-
notch = rcParams['boxplot.notch']
3833+
notch = mpl.rcParams['boxplot.notch']
38323834
if vert is None:
3833-
vert = rcParams['boxplot.vertical']
3835+
vert = mpl.rcParams['boxplot.vertical']
38343836
if patch_artist is None:
3835-
patch_artist = rcParams['boxplot.patchartist']
3837+
patch_artist = mpl.rcParams['boxplot.patchartist']
38363838
if meanline is None:
3837-
meanline = rcParams['boxplot.meanline']
3839+
meanline = mpl.rcParams['boxplot.meanline']
38383840
if showmeans is None:
3839-
showmeans = rcParams['boxplot.showmeans']
3841+
showmeans = mpl.rcParams['boxplot.showmeans']
38403842
if showcaps is None:
3841-
showcaps = rcParams['boxplot.showcaps']
3843+
showcaps = mpl.rcParams['boxplot.showcaps']
38423844
if showbox is None:
3843-
showbox = rcParams['boxplot.showbox']
3845+
showbox = mpl.rcParams['boxplot.showbox']
38443846
if showfliers is None:
3845-
showfliers = rcParams['boxplot.showfliers']
3847+
showfliers = mpl.rcParams['boxplot.showfliers']
38463848

38473849
if boxprops is None:
38483850
boxprops = {}
@@ -4050,7 +4052,7 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
40504052
zdelta = 0.1
40514053

40524054
def merge_kw_rc(subkey, explicit, zdelta=0, usemarker=True):
4053-
d = {k.split('.')[-1]: v for k, v in rcParams.items()
4055+
d = {k.split('.')[-1]: v for k, v in mpl.rcParams.items()
40544056
if k.startswith(f'boxplot.{subkey}props')}
40554057
d['zorder'] = zorder + zdelta
40564058
if not usemarker:
@@ -4059,11 +4061,11 @@ def merge_kw_rc(subkey, explicit, zdelta=0, usemarker=True):
40594061
return d
40604062

40614063
box_kw = {
4062-
'linestyle': rcParams['boxplot.boxprops.linestyle'],
4063-
'linewidth': rcParams['boxplot.boxprops.linewidth'],
4064-
'edgecolor': rcParams['boxplot.boxprops.color'],
4065-
'facecolor': ('white' if rcParams['_internal.classic_mode']
4066-
else rcParams['patch.facecolor']),
4064+
'linestyle': mpl.rcParams['boxplot.boxprops.linestyle'],
4065+
'linewidth': mpl.rcParams['boxplot.boxprops.linewidth'],
4066+
'edgecolor': mpl.rcParams['boxplot.boxprops.color'],
4067+
'facecolor': ('white' if mpl.rcParams['_internal.classic_mode']
4068+
else mpl.rcParams['patch.facecolor']),
40674069
'zorder': zorder,
40684070
**cbook.normalize_kwargs(boxprops, mpatches.PathPatch)
40694071
} if patch_artist else merge_kw_rc('box', boxprops, usemarker=False)
@@ -4300,13 +4302,13 @@ def _parse_scatter_color_args(c, edgecolors, kwargs, xsize,
43004302
if facecolors is None:
43014303
facecolors = kwcolor
43024304

4303-
if edgecolors is None and not rcParams['_internal.classic_mode']:
4304-
edgecolors = rcParams['scatter.edgecolors']
4305+
if edgecolors is None and not mpl.rcParams['_internal.classic_mode']:
4306+
edgecolors = mpl.rcParams['scatter.edgecolors']
43054307

43064308
c_was_none = c is None
43074309
if c is None:
43084310
c = (facecolors if facecolors is not None
4309-
else "b" if rcParams['_internal.classic_mode']
4311+
else "b" if mpl.rcParams['_internal.classic_mode']
43104312
else get_next_color_func())
43114313
c_is_string_or_strings = (
43124314
isinstance(c, str)
@@ -4498,8 +4500,8 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
44984500
raise ValueError("x and y must be the same size")
44994501

45004502
if s is None:
4501-
s = (20 if rcParams['_internal.classic_mode'] else
4502-
rcParams['lines.markersize'] ** 2.0)
4503+
s = (20 if mpl.rcParams['_internal.classic_mode'] else
4504+
mpl.rcParams['lines.markersize'] ** 2.0)
45034505
s = np.ma.ravel(s)
45044506
if (len(s) not in (1, x.size) or
45054507
(not np.issubdtype(s.dtype, np.floating) and
@@ -4535,7 +4537,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
45354537

45364538
# load default marker from rcParams
45374539
if marker is None:
4538-
marker = rcParams['scatter.marker']
4540+
marker = mpl.rcParams['scatter.marker']
45394541

45404542
if isinstance(marker, mmarkers.MarkerStyle):
45414543
marker_obj = marker
@@ -4576,10 +4578,10 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
45764578
edgecolors = 'face'
45774579

45784580
if linewidths is None:
4579-
linewidths = rcParams['lines.linewidth']
4581+
linewidths = mpl.rcParams['lines.linewidth']
45804582
elif np.iterable(linewidths):
45814583
linewidths = [
4582-
lw if lw is not None else rcParams['lines.linewidth']
4584+
lw if lw is not None else mpl.rcParams['lines.linewidth']
45834585
for lw in linewidths]
45844586

45854587
offsets = np.ma.column_stack([x, y])
@@ -4616,7 +4618,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
46164618
# finite size of the symbols. In v2.x, margins
46174619
# are present by default, so we disable this
46184620
# scatter-specific override.
4619-
if rcParams['_internal.classic_mode']:
4621+
if mpl.rcParams['_internal.classic_mode']:
46204622
if self._xmargin < 0.05 and x.size > 0:
46214623
self.set_xmargin(0.05)
46224624
if self._ymargin < 0.05 and x.size > 0:
@@ -5216,7 +5218,7 @@ def _fill_between_x_or_y(
52165218

52175219
dep_dir = {"x": "y", "y": "x"}[ind_dir]
52185220

5219-
if not rcParams["_internal.classic_mode"]:
5221+
if not mpl.rcParams["_internal.classic_mode"]:
52205222
kwargs = cbook.normalize_kwargs(kwargs, mcoll.Collection)
52215223
if not any(c in kwargs for c in ("color", "facecolor")):
52225224
kwargs["facecolor"] = \
@@ -5546,7 +5548,7 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
55465548
(unassociated) alpha representation.
55475549
"""
55485550
if aspect is None:
5549-
aspect = rcParams['image.aspect']
5551+
aspect = mpl.rcParams['image.aspect']
55505552
self.set_aspect(aspect)
55515553
im = mimage.AxesImage(self, cmap=cmap, norm=norm,
55525554
interpolation=interpolation, origin=origin,
@@ -5846,7 +5848,7 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
58465848
"""
58475849

58485850
if shading is None:
5849-
shading = rcParams['pcolor.shading']
5851+
shading = mpl.rcParams['pcolor.shading']
58505852
shading = shading.lower()
58515853
X, Y, C, shading = self._pcolorargs('pcolor', *args, shading=shading,
58525854
kwargs=kwargs)
@@ -6110,7 +6112,7 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
61106112
61116113
"""
61126114
if shading is None:
6113-
shading = rcParams['pcolor.shading']
6115+
shading = mpl.rcParams['pcolor.shading']
61146116
shading = shading.lower()
61156117
kwargs.setdefault('edgecolors', 'none')
61166118

@@ -6120,7 +6122,7 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
61206122
# convert to one dimensional array
61216123
C = C.ravel()
61226124

6123-
kwargs.setdefault('snap', rcParams['pcolormesh.snap'])
6125+
kwargs.setdefault('snap', mpl.rcParams['pcolormesh.snap'])
61246126

61256127
collection = mcoll.QuadMesh(
61266128
coords, antialiased=antialiased, shading=shading,
@@ -6588,7 +6590,7 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
65886590
x = [x]
65896591

65906592
if bins is None:
6591-
bins = rcParams['hist.bins']
6593+
bins = mpl.rcParams['hist.bins']
65926594

65936595
# Validate string inputs here to avoid cluttering subsequent code.
65946596
_api.check_in_list(['bar', 'barstacked', 'step', 'stepfilled'],
@@ -6715,7 +6717,7 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
67156717
if rwidth is not None:
67166718
dr = np.clip(rwidth, 0, 1)
67176719
elif (len(tops) > 1 and
6718-
((not stacked) or rcParams['_internal.classic_mode'])):
6720+
((not stacked) or mpl.rcParams['_internal.classic_mode'])):
67196721
dr = 0.8
67206722
else:
67216723
dr = 1.0
@@ -8111,7 +8113,7 @@ def violin(self, vpstats, positions=None, vert=True, widths=0.5,
81118113
line_ends = [[-0.25], [0.25]] * np.array(widths) + positions
81128114

81138115
# Colors.
8114-
if rcParams['_internal.classic_mode']:
8116+
if mpl.rcParams['_internal.classic_mode']:
81158117
fillcolor = 'y'
81168118
linecolor = 'r'
81178119
else:

‎lib/matplotlib/colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colors.py
+1-2Lines 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:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.