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 baaec37

Browse filesBrowse files
authored
Merge pull request #16780 from timhoffm/mpl-rcParams
Don't import rcParams but rather use mpl.rcParams (part 3)
2 parents 30282cf + c083448 commit baaec37
Copy full SHA for baaec37

File tree

Expand file treeCollapse file tree

6 files changed

+49
-49
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+49
-49
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+21-20Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy as np
1111

1212
import matplotlib as mpl
13-
from matplotlib import cbook, rcParams
13+
from matplotlib import cbook
1414
from matplotlib.cbook import _OrderedSet, _check_1d, index_of
1515
from matplotlib import docstring
1616
import matplotlib.colors as mcolors
@@ -106,7 +106,7 @@ def _process_plot_format(fmt):
106106
'Unrecognized character %c in format string' % c)
107107

108108
if linestyle is None and marker is None:
109-
linestyle = rcParams['lines.linestyle']
109+
linestyle = mpl.rcParams['lines.linestyle']
110110
if linestyle is None:
111111
linestyle = 'None'
112112
if marker is None:
@@ -142,7 +142,7 @@ def __setstate__(self, state):
142142
def set_prop_cycle(self, *args, **kwargs):
143143
# Can't do `args == (None,)` as that crashes cycler.
144144
if not (args or kwargs) or (len(args) == 1 and args[0] is None):
145-
prop_cycler = rcParams['axes.prop_cycle']
145+
prop_cycler = mpl.rcParams['axes.prop_cycle']
146146
else:
147147
prop_cycler = cycler(*args, **kwargs)
148148

@@ -453,10 +453,10 @@ def __init__(self, fig, rect,
453453
# this call may differ for non-sep axes, e.g., polar
454454
self._init_axis()
455455
if facecolor is None:
456-
facecolor = rcParams['axes.facecolor']
456+
facecolor = mpl.rcParams['axes.facecolor']
457457
self._facecolor = facecolor
458458
self._frameon = frameon
459-
self.set_axisbelow(rcParams['axes.axisbelow'])
459+
self.set_axisbelow(mpl.rcParams['axes.axisbelow'])
460460

461461
self._rasterization_zorder = None
462462
self.cla()
@@ -483,6 +483,7 @@ def __init__(self, fig, rect,
483483
self._ycid = self.yaxis.callbacks.connect(
484484
'units finalize', lambda: self._on_units_changed(scaley=True))
485485

486+
rcParams = mpl.rcParams
486487
self.tick_params(
487488
top=rcParams['xtick.top'] and rcParams['xtick.minor.top'],
488489
bottom=rcParams['xtick.bottom'] and rcParams['xtick.minor.bottom'],
@@ -697,7 +698,7 @@ def get_xaxis_text1_transform(self, pad_points):
697698
class, and is meant to be overridden by new kinds of projections that
698699
may need to place axis elements in different locations.
699700
"""
700-
labels_align = rcParams["xtick.alignment"]
701+
labels_align = mpl.rcParams["xtick.alignment"]
701702
return (self.get_xaxis_transform(which='tick1') +
702703
mtransforms.ScaledTranslation(0, -1 * pad_points / 72,
703704
self.figure.dpi_scale_trans),
@@ -723,7 +724,7 @@ def get_xaxis_text2_transform(self, pad_points):
723724
class, and is meant to be overridden by new kinds of projections that
724725
may need to place axis elements in different locations.
725726
"""
726-
labels_align = rcParams["xtick.alignment"]
727+
labels_align = mpl.rcParams["xtick.alignment"]
727728
return (self.get_xaxis_transform(which='tick2') +
728729
mtransforms.ScaledTranslation(0, pad_points / 72,
729730
self.figure.dpi_scale_trans),
@@ -773,7 +774,7 @@ def get_yaxis_text1_transform(self, pad_points):
773774
class, and is meant to be overridden by new kinds of projections that
774775
may need to place axis elements in different locations.
775776
"""
776-
labels_align = rcParams["ytick.alignment"]
777+
labels_align = mpl.rcParams["ytick.alignment"]
777778
return (self.get_yaxis_transform(which='tick1') +
778779
mtransforms.ScaledTranslation(-1 * pad_points / 72, 0,
779780
self.figure.dpi_scale_trans),
@@ -799,7 +800,7 @@ def get_yaxis_text2_transform(self, pad_points):
799800
class, and is meant to be overridden by new kinds of projections that
800801
may need to place axis elements in different locations.
801802
"""
802-
labels_align = rcParams["ytick.alignment"]
803+
labels_align = mpl.rcParams["ytick.alignment"]
803804
return (self.get_yaxis_transform(which='tick2') +
804805
mtransforms.ScaledTranslation(pad_points / 72, 0,
805806
self.figure.dpi_scale_trans),
@@ -1005,26 +1006,26 @@ def cla(self):
10051006
except TypeError:
10061007
pass
10071008
# update the minor locator for x and y axis based on rcParams
1008-
if rcParams['xtick.minor.visible']:
1009+
if mpl.rcParams['xtick.minor.visible']:
10091010
self.xaxis.set_minor_locator(mticker.AutoMinorLocator())
10101011

1011-
if rcParams['ytick.minor.visible']:
1012+
if mpl.rcParams['ytick.minor.visible']:
10121013
self.yaxis.set_minor_locator(mticker.AutoMinorLocator())
10131014

10141015
if self._sharex is None:
10151016
self._autoscaleXon = True
10161017
if self._sharey is None:
10171018
self._autoscaleYon = True
1018-
self._xmargin = rcParams['axes.xmargin']
1019-
self._ymargin = rcParams['axes.ymargin']
1019+
self._xmargin = mpl.rcParams['axes.xmargin']
1020+
self._ymargin = mpl.rcParams['axes.ymargin']
10201021
self._tight = None
10211022
self._use_sticky_edges = True
10221023
self._update_transScale() # needed?
10231024

10241025
self._get_lines = _process_plot_var_args(self)
10251026
self._get_patches_for_fill = _process_plot_var_args(self, 'fill')
10261027

1027-
self._gridOn = rcParams['axes.grid']
1028+
self._gridOn = mpl.rcParams['axes.grid']
10281029
self.lines = []
10291030
self.patches = []
10301031
self.texts = []
@@ -1039,11 +1040,11 @@ def cla(self):
10391040
self.containers = []
10401041

10411042
self.grid(False) # Disable grid on init to use rcParameter
1042-
self.grid(self._gridOn, which=rcParams['axes.grid.which'],
1043-
axis=rcParams['axes.grid.axis'])
1043+
self.grid(self._gridOn, which=mpl.rcParams['axes.grid.which'],
1044+
axis=mpl.rcParams['axes.grid.axis'])
10441045
props = font_manager.FontProperties(
1045-
size=rcParams['axes.titlesize'],
1046-
weight=rcParams['axes.titleweight'])
1046+
size=mpl.rcParams['axes.titlesize'],
1047+
weight=mpl.rcParams['axes.titleweight'])
10471048

10481049
self.title = mtext.Text(
10491050
x=0.5, y=1.0, text='',
@@ -1062,7 +1063,7 @@ def cla(self):
10621063
verticalalignment='baseline',
10631064
horizontalalignment='right',
10641065
)
1065-
title_offset_points = rcParams['axes.titlepad']
1066+
title_offset_points = mpl.rcParams['axes.titlepad']
10661067
# refactor this out so it can be called in ax.set_title if
10671068
# pad argument used...
10681069
self._set_title_offset_trans(title_offset_points)
@@ -1121,7 +1122,7 @@ def set_facecolor(self, color):
11211122

11221123
def _set_title_offset_trans(self, title_offset_points):
11231124
"""
1124-
Set the offset for the title either from rcParams['axes.titlepad']
1125+
Set the offset for the title either from :rc:`axes.titlepad`
11251126
or from set_title kwarg ``pad``.
11261127
"""
11271128
self.titleOffsetTrans = mtransforms.ScaledTranslation(

‎lib/matplotlib/backends/qt_compat.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/qt_compat.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import os
1616
import sys
1717

18-
from matplotlib import rcParams
18+
import matplotlib as mpl
1919

2020

2121
QT_API_PYQT5 = "PyQt5"
@@ -41,12 +41,12 @@
4141
# Otherwise, check the QT_API environment variable (from Enthought). This can
4242
# only override the binding, not the backend (in other words, we check that the
4343
# requested backend actually matches).
44-
elif rcParams["backend"] in ["Qt5Agg", "Qt5Cairo"]:
44+
elif mpl.rcParams["backend"] in ["Qt5Agg", "Qt5Cairo"]:
4545
if QT_API_ENV in ["pyqt5", "pyside2"]:
4646
QT_API = _ETS[QT_API_ENV]
4747
else:
4848
QT_API = None
49-
elif rcParams["backend"] in ["Qt4Agg", "Qt4Cairo"]:
49+
elif mpl.rcParams["backend"] in ["Qt4Agg", "Qt4Cairo"]:
5050
if QT_API_ENV in ["pyqt4", "pyside"]:
5151
QT_API = _ETS[QT_API_ENV]
5252
else:
@@ -147,7 +147,7 @@ def is_pyqt5():
147147
elif QT_API in [QT_API_PYQTv2, QT_API_PYSIDE, QT_API_PYQT]:
148148
_setup_pyqt4()
149149
elif QT_API is None:
150-
if rcParams["backend"] == "Qt4Agg":
150+
if mpl.rcParams["backend"] == "Qt4Agg":
151151
_candidates = [(_setup_pyqt4, QT_API_PYQTv2),
152152
(_setup_pyqt4, QT_API_PYSIDE),
153153
(_setup_pyqt4, QT_API_PYQT),

‎lib/matplotlib/dates.py

Copy file name to clipboardExpand all lines: lib/matplotlib/dates.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@
147147
import numpy as np
148148

149149
import matplotlib
150-
from matplotlib import rcParams
151150
import matplotlib.units as units
152151
import matplotlib.cbook as cbook
153152
import matplotlib.ticker as ticker
@@ -828,6 +827,7 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
828827
self._tz = tz
829828
self.defaultfmt = defaultfmt
830829
self._formatter = DateFormatter(self.defaultfmt, tz)
830+
rcParams = matplotlib.rcParams
831831
self.scaled = {
832832
DAYS_PER_YEAR: rcParams['date.autoformatter.year'],
833833
DAYS_PER_MONTH: rcParams['date.autoformatter.month'],

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+19-19Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import numpy as np
1515

16-
from matplotlib import rcParams
16+
import matplotlib as mpl
1717
from matplotlib import docstring, projections
1818
from matplotlib import __version__ as _mpl_version
1919

@@ -187,7 +187,7 @@ def __init__(self, left=None, bottom=None, right=None, top=None,
187187
"""
188188
self.validate = True
189189
for key in ["left", "bottom", "right", "top", "wspace", "hspace"]:
190-
setattr(self, key, rcParams[f"figure.subplot.{key}"])
190+
setattr(self, key, mpl.rcParams[f"figure.subplot.{key}"])
191191
self.update(left, bottom, right, top, wspace, hspace)
192192

193193
def update(self, left=None, bottom=None, right=None, top=None,
@@ -307,15 +307,15 @@ def __init__(self,
307307
self.callbacks = cbook.CallbackRegistry()
308308

309309
if figsize is None:
310-
figsize = rcParams['figure.figsize']
310+
figsize = mpl.rcParams['figure.figsize']
311311
if dpi is None:
312-
dpi = rcParams['figure.dpi']
312+
dpi = mpl.rcParams['figure.dpi']
313313
if facecolor is None:
314-
facecolor = rcParams['figure.facecolor']
314+
facecolor = mpl.rcParams['figure.facecolor']
315315
if edgecolor is None:
316-
edgecolor = rcParams['figure.edgecolor']
316+
edgecolor = mpl.rcParams['figure.edgecolor']
317317
if frameon is None:
318-
frameon = rcParams['figure.frameon']
318+
frameon = mpl.rcParams['figure.frameon']
319319

320320
if not np.isfinite(figsize).all() or (np.array(figsize) <= 0).any():
321321
raise ValueError('figure size must be positive finite not '
@@ -467,7 +467,7 @@ def set_tight_layout(self, tight):
467467
default paddings.
468468
"""
469469
if tight is None:
470-
tight = rcParams['figure.autolayout']
470+
tight = mpl.rcParams['figure.autolayout']
471471
self._tight = bool(tight)
472472
self._tight_parameters = tight if isinstance(tight, dict) else {}
473473
self.stale = True
@@ -483,7 +483,7 @@ def get_constrained_layout(self):
483483
def set_constrained_layout(self, constrained):
484484
"""
485485
Set whether ``constrained_layout`` is used upon drawing. If None,
486-
the rcParams['figure.constrained_layout.use'] value will be used.
486+
:rc:`figure.constrained_layout.use` value will be used.
487487
488488
When providing a dict containing the keys `w_pad`, `h_pad`
489489
the default ``constrained_layout`` paddings will be
@@ -502,7 +502,7 @@ def set_constrained_layout(self, constrained):
502502
self._constrained_layout_pads['wspace'] = None
503503
self._constrained_layout_pads['hspace'] = None
504504
if constrained is None:
505-
constrained = rcParams['figure.constrained_layout.use']
505+
constrained = mpl.rcParams['figure.constrained_layout.use']
506506
self._constrained = bool(constrained)
507507
if isinstance(constrained, dict):
508508
self.set_constrained_layout_pads(**constrained)
@@ -544,7 +544,7 @@ def set_constrained_layout_pads(self, **kwargs):
544544
self._constrained_layout_pads[td] = kwargs[td]
545545
else:
546546
self._constrained_layout_pads[td] = (
547-
rcParams['figure.constrained_layout.' + td])
547+
mpl.rcParams['figure.constrained_layout.' + td])
548548

549549
def get_constrained_layout_pads(self, relative=False):
550550
"""
@@ -713,9 +713,9 @@ def suptitle(self, t, **kwargs):
713713

714714
if 'fontproperties' not in kwargs:
715715
if 'fontsize' not in kwargs and 'size' not in kwargs:
716-
kwargs['size'] = rcParams['figure.titlesize']
716+
kwargs['size'] = mpl.rcParams['figure.titlesize']
717717
if 'fontweight' not in kwargs and 'weight' not in kwargs:
718-
kwargs['weight'] = rcParams['figure.titleweight']
718+
kwargs['weight'] = mpl.rcParams['figure.titleweight']
719719

720720
sup = self.text(x, y, t, **kwargs)
721721
if self._suptitle is not None:
@@ -1840,7 +1840,7 @@ def text(self, x, y, s, fontdict=None, **kwargs):
18401840
18411841
fontdict : dict, optional
18421842
A dictionary to override the default text properties. If not given,
1843-
the defaults are determined by `.rcParams`. Properties passed as
1843+
the defaults are determined by :rc:`font.*`. Properties passed as
18441844
*kwargs* override the corresponding ones given in *fontdict*.
18451845
18461846
Other Parameters
@@ -2164,9 +2164,9 @@ def savefig(self, fname, *, transparent=None, **kwargs):
21642164
`PIL.Image.Image.save` when saving the figure.
21652165
"""
21662166

2167-
kwargs.setdefault('dpi', rcParams['savefig.dpi'])
2167+
kwargs.setdefault('dpi', mpl.rcParams['savefig.dpi'])
21682168
if transparent is None:
2169-
transparent = rcParams['savefig.transparent']
2169+
transparent = mpl.rcParams['savefig.transparent']
21702170

21712171
if transparent:
21722172
kwargs.setdefault('facecolor', 'none')
@@ -2179,8 +2179,8 @@ def savefig(self, fname, *, transparent=None, **kwargs):
21792179
patch.set_facecolor('none')
21802180
patch.set_edgecolor('none')
21812181
else:
2182-
kwargs.setdefault('facecolor', rcParams['savefig.facecolor'])
2183-
kwargs.setdefault('edgecolor', rcParams['savefig.edgecolor'])
2182+
kwargs.setdefault('facecolor', mpl.rcParams['savefig.facecolor'])
2183+
kwargs.setdefault('edgecolor', mpl.rcParams['savefig.edgecolor'])
21842184

21852185
self.canvas.print_figure(fname, **kwargs)
21862186

@@ -2734,7 +2734,7 @@ def figaspect(arg):
27342734
arr_ratio = arg
27352735

27362736
# Height of user figure defaults
2737-
fig_height = rcParams['figure.figsize'][1]
2737+
fig_height = mpl.rcParams['figure.figsize'][1]
27382738

27392739
# New size for the figure, keeping the aspect ratio of the caller
27402740
newsize = np.array((fig_height / arr_ratio, fig_height))

‎lib/matplotlib/sankey.py

Copy file name to clipboardExpand all lines: lib/matplotlib/sankey.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
import numpy as np
99

10+
import matplotlib as mpl
1011
from matplotlib.path import Path
1112
from matplotlib.patches import PathPatch
1213
from matplotlib.transforms import Affine2D
1314
from matplotlib import docstring
14-
from matplotlib import rcParams
1515

1616
_log = logging.getLogger(__name__)
1717

@@ -718,7 +718,7 @@ def _get_angle(a, r):
718718
vertices = translate(rotate(vertices))
719719
kwds = dict(s=patchlabel, ha='center', va='center')
720720
text = self.ax.text(*offset, **kwds)
721-
if rcParams['_internal.classic_mode']:
721+
if mpl.rcParams['_internal.classic_mode']:
722722
fc = kwargs.pop('fc', kwargs.pop('facecolor', '#bfd1d4'))
723723
lw = kwargs.pop('lw', kwargs.pop('linewidth', 0.5))
724724
else:

‎lib/matplotlib/tests/test_backend_qt.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_qt.py
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import matplotlib
77
from matplotlib import pyplot as plt
8-
from matplotlib import rcParams
98
from matplotlib._pylab_helpers import Gcf
109

1110
import pytest
@@ -246,8 +245,8 @@ def test_double_resize():
246245

247246
w, h = 3, 2
248247
fig.set_size_inches(w, h)
249-
assert fig.canvas.width() == w * rcParams['figure.dpi']
250-
assert fig.canvas.height() == h * rcParams['figure.dpi']
248+
assert fig.canvas.width() == w * matplotlib.rcParams['figure.dpi']
249+
assert fig.canvas.height() == h * matplotlib.rcParams['figure.dpi']
251250

252251
old_width = window.width()
253252
old_height = window.height()

0 commit comments

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