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

Skip to content

Don't import rcParams but rather use mpl.rcParams (part 3) #16780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import numpy as np

import matplotlib as mpl
from matplotlib import cbook, rcParams
from matplotlib import cbook
from matplotlib.cbook import _OrderedSet, _check_1d, index_of
from matplotlib import docstring
import matplotlib.colors as mcolors
Expand Down Expand Up @@ -106,7 +106,7 @@ def _process_plot_format(fmt):
'Unrecognized character %c in format string' % c)

if linestyle is None and marker is None:
linestyle = rcParams['lines.linestyle']
linestyle = mpl.rcParams['lines.linestyle']
if linestyle is None:
linestyle = 'None'
if marker is None:
Expand Down Expand Up @@ -142,7 +142,7 @@ def __setstate__(self, state):
def set_prop_cycle(self, *args, **kwargs):
# Can't do `args == (None,)` as that crashes cycler.
if not (args or kwargs) or (len(args) == 1 and args[0] is None):
prop_cycler = rcParams['axes.prop_cycle']
prop_cycler = mpl.rcParams['axes.prop_cycle']
else:
prop_cycler = cycler(*args, **kwargs)

Expand Down Expand Up @@ -453,10 +453,10 @@ def __init__(self, fig, rect,
# this call may differ for non-sep axes, e.g., polar
self._init_axis()
if facecolor is None:
facecolor = rcParams['axes.facecolor']
facecolor = mpl.rcParams['axes.facecolor']
self._facecolor = facecolor
self._frameon = frameon
self.set_axisbelow(rcParams['axes.axisbelow'])
self.set_axisbelow(mpl.rcParams['axes.axisbelow'])

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

rcParams = mpl.rcParams
self.tick_params(
top=rcParams['xtick.top'] and rcParams['xtick.minor.top'],
bottom=rcParams['xtick.bottom'] and rcParams['xtick.minor.bottom'],
Expand Down Expand Up @@ -697,7 +698,7 @@ def get_xaxis_text1_transform(self, pad_points):
class, and is meant to be overridden by new kinds of projections that
may need to place axis elements in different locations.
"""
labels_align = rcParams["xtick.alignment"]
labels_align = mpl.rcParams["xtick.alignment"]
return (self.get_xaxis_transform(which='tick1') +
mtransforms.ScaledTranslation(0, -1 * pad_points / 72,
self.figure.dpi_scale_trans),
Expand All @@ -723,7 +724,7 @@ def get_xaxis_text2_transform(self, pad_points):
class, and is meant to be overridden by new kinds of projections that
may need to place axis elements in different locations.
"""
labels_align = rcParams["xtick.alignment"]
labels_align = mpl.rcParams["xtick.alignment"]
return (self.get_xaxis_transform(which='tick2') +
mtransforms.ScaledTranslation(0, pad_points / 72,
self.figure.dpi_scale_trans),
Expand Down Expand Up @@ -773,7 +774,7 @@ def get_yaxis_text1_transform(self, pad_points):
class, and is meant to be overridden by new kinds of projections that
may need to place axis elements in different locations.
"""
labels_align = rcParams["ytick.alignment"]
labels_align = mpl.rcParams["ytick.alignment"]
return (self.get_yaxis_transform(which='tick1') +
mtransforms.ScaledTranslation(-1 * pad_points / 72, 0,
self.figure.dpi_scale_trans),
Expand All @@ -799,7 +800,7 @@ def get_yaxis_text2_transform(self, pad_points):
class, and is meant to be overridden by new kinds of projections that
may need to place axis elements in different locations.
"""
labels_align = rcParams["ytick.alignment"]
labels_align = mpl.rcParams["ytick.alignment"]
return (self.get_yaxis_transform(which='tick2') +
mtransforms.ScaledTranslation(pad_points / 72, 0,
self.figure.dpi_scale_trans),
Expand Down Expand Up @@ -1005,26 +1006,26 @@ def cla(self):
except TypeError:
pass
# update the minor locator for x and y axis based on rcParams
if rcParams['xtick.minor.visible']:
if mpl.rcParams['xtick.minor.visible']:
self.xaxis.set_minor_locator(mticker.AutoMinorLocator())

if rcParams['ytick.minor.visible']:
if mpl.rcParams['ytick.minor.visible']:
self.yaxis.set_minor_locator(mticker.AutoMinorLocator())

if self._sharex is None:
self._autoscaleXon = True
if self._sharey is None:
self._autoscaleYon = True
self._xmargin = rcParams['axes.xmargin']
self._ymargin = rcParams['axes.ymargin']
self._xmargin = mpl.rcParams['axes.xmargin']
self._ymargin = mpl.rcParams['axes.ymargin']
self._tight = None
self._use_sticky_edges = True
self._update_transScale() # needed?

self._get_lines = _process_plot_var_args(self)
self._get_patches_for_fill = _process_plot_var_args(self, 'fill')

self._gridOn = rcParams['axes.grid']
self._gridOn = mpl.rcParams['axes.grid']
self.lines = []
self.patches = []
self.texts = []
Expand All @@ -1039,11 +1040,11 @@ def cla(self):
self.containers = []

self.grid(False) # Disable grid on init to use rcParameter
self.grid(self._gridOn, which=rcParams['axes.grid.which'],
axis=rcParams['axes.grid.axis'])
self.grid(self._gridOn, which=mpl.rcParams['axes.grid.which'],
axis=mpl.rcParams['axes.grid.axis'])
props = font_manager.FontProperties(
size=rcParams['axes.titlesize'],
weight=rcParams['axes.titleweight'])
size=mpl.rcParams['axes.titlesize'],
weight=mpl.rcParams['axes.titleweight'])

self.title = mtext.Text(
x=0.5, y=1.0, text='',
Expand All @@ -1062,7 +1063,7 @@ def cla(self):
verticalalignment='baseline',
horizontalalignment='right',
)
title_offset_points = rcParams['axes.titlepad']
title_offset_points = mpl.rcParams['axes.titlepad']
# refactor this out so it can be called in ax.set_title if
# pad argument used...
self._set_title_offset_trans(title_offset_points)
Expand Down Expand Up @@ -1121,7 +1122,7 @@ def set_facecolor(self, color):

def _set_title_offset_trans(self, title_offset_points):
"""
Set the offset for the title either from rcParams['axes.titlepad']
Set the offset for the title either from :rc:`axes.titlepad`
or from set_title kwarg ``pad``.
"""
self.titleOffsetTrans = mtransforms.ScaledTranslation(
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os
import sys

from matplotlib import rcParams
import matplotlib as mpl


QT_API_PYQT5 = "PyQt5"
Expand All @@ -41,12 +41,12 @@
# Otherwise, check the QT_API environment variable (from Enthought). This can
# only override the binding, not the backend (in other words, we check that the
# requested backend actually matches).
elif rcParams["backend"] in ["Qt5Agg", "Qt5Cairo"]:
elif mpl.rcParams["backend"] in ["Qt5Agg", "Qt5Cairo"]:
if QT_API_ENV in ["pyqt5", "pyside2"]:
QT_API = _ETS[QT_API_ENV]
else:
QT_API = None
elif rcParams["backend"] in ["Qt4Agg", "Qt4Cairo"]:
elif mpl.rcParams["backend"] in ["Qt4Agg", "Qt4Cairo"]:
if QT_API_ENV in ["pyqt4", "pyside"]:
QT_API = _ETS[QT_API_ENV]
else:
Expand Down Expand Up @@ -147,7 +147,7 @@ def is_pyqt5():
elif QT_API in [QT_API_PYQTv2, QT_API_PYSIDE, QT_API_PYQT]:
_setup_pyqt4()
elif QT_API is None:
if rcParams["backend"] == "Qt4Agg":
if mpl.rcParams["backend"] == "Qt4Agg":
_candidates = [(_setup_pyqt4, QT_API_PYQTv2),
(_setup_pyqt4, QT_API_PYSIDE),
(_setup_pyqt4, QT_API_PYQT),
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
import numpy as np

import matplotlib
from matplotlib import rcParams
import matplotlib.units as units
import matplotlib.cbook as cbook
import matplotlib.ticker as ticker
Expand Down Expand Up @@ -828,6 +827,7 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
self._tz = tz
self.defaultfmt = defaultfmt
self._formatter = DateFormatter(self.defaultfmt, tz)
rcParams = matplotlib.rcParams
self.scaled = {
DAYS_PER_YEAR: rcParams['date.autoformatter.year'],
DAYS_PER_MONTH: rcParams['date.autoformatter.month'],
Expand Down
38 changes: 19 additions & 19 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import numpy as np

from matplotlib import rcParams
import matplotlib as mpl
from matplotlib import docstring, projections
from matplotlib import __version__ as _mpl_version

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

def update(self, left=None, bottom=None, right=None, top=None,
Expand Down Expand Up @@ -307,15 +307,15 @@ def __init__(self,
self.callbacks = cbook.CallbackRegistry()

if figsize is None:
figsize = rcParams['figure.figsize']
figsize = mpl.rcParams['figure.figsize']
if dpi is None:
dpi = rcParams['figure.dpi']
dpi = mpl.rcParams['figure.dpi']
if facecolor is None:
facecolor = rcParams['figure.facecolor']
facecolor = mpl.rcParams['figure.facecolor']
if edgecolor is None:
edgecolor = rcParams['figure.edgecolor']
edgecolor = mpl.rcParams['figure.edgecolor']
if frameon is None:
frameon = rcParams['figure.frameon']
frameon = mpl.rcParams['figure.frameon']

if not np.isfinite(figsize).all() or (np.array(figsize) <= 0).any():
raise ValueError('figure size must be positive finite not '
Expand Down Expand Up @@ -467,7 +467,7 @@ def set_tight_layout(self, tight):
default paddings.
"""
if tight is None:
tight = rcParams['figure.autolayout']
tight = mpl.rcParams['figure.autolayout']
self._tight = bool(tight)
self._tight_parameters = tight if isinstance(tight, dict) else {}
self.stale = True
Expand All @@ -483,7 +483,7 @@ def get_constrained_layout(self):
def set_constrained_layout(self, constrained):
"""
Set whether ``constrained_layout`` is used upon drawing. If None,
the rcParams['figure.constrained_layout.use'] value will be used.
:rc:`figure.constrained_layout.use` value will be used.

When providing a dict containing the keys `w_pad`, `h_pad`
the default ``constrained_layout`` paddings will be
Expand All @@ -502,7 +502,7 @@ def set_constrained_layout(self, constrained):
self._constrained_layout_pads['wspace'] = None
self._constrained_layout_pads['hspace'] = None
if constrained is None:
constrained = rcParams['figure.constrained_layout.use']
constrained = mpl.rcParams['figure.constrained_layout.use']
self._constrained = bool(constrained)
if isinstance(constrained, dict):
self.set_constrained_layout_pads(**constrained)
Expand Down Expand Up @@ -544,7 +544,7 @@ def set_constrained_layout_pads(self, **kwargs):
self._constrained_layout_pads[td] = kwargs[td]
else:
self._constrained_layout_pads[td] = (
rcParams['figure.constrained_layout.' + td])
mpl.rcParams['figure.constrained_layout.' + td])

def get_constrained_layout_pads(self, relative=False):
"""
Expand Down Expand Up @@ -713,9 +713,9 @@ def suptitle(self, t, **kwargs):

if 'fontproperties' not in kwargs:
if 'fontsize' not in kwargs and 'size' not in kwargs:
kwargs['size'] = rcParams['figure.titlesize']
kwargs['size'] = mpl.rcParams['figure.titlesize']
if 'fontweight' not in kwargs and 'weight' not in kwargs:
kwargs['weight'] = rcParams['figure.titleweight']
kwargs['weight'] = mpl.rcParams['figure.titleweight']

sup = self.text(x, y, t, **kwargs)
if self._suptitle is not None:
Expand Down Expand Up @@ -1840,7 +1840,7 @@ def text(self, x, y, s, fontdict=None, **kwargs):

fontdict : dict, optional
A dictionary to override the default text properties. If not given,
the defaults are determined by `.rcParams`. Properties passed as
the defaults are determined by :rc:`font.*`. Properties passed as
*kwargs* override the corresponding ones given in *fontdict*.

Other Parameters
Expand Down Expand Up @@ -2164,9 +2164,9 @@ def savefig(self, fname, *, transparent=None, **kwargs):
`PIL.Image.Image.save` when saving the figure.
"""

kwargs.setdefault('dpi', rcParams['savefig.dpi'])
kwargs.setdefault('dpi', mpl.rcParams['savefig.dpi'])
if transparent is None:
transparent = rcParams['savefig.transparent']
transparent = mpl.rcParams['savefig.transparent']

if transparent:
kwargs.setdefault('facecolor', 'none')
Expand All @@ -2179,8 +2179,8 @@ def savefig(self, fname, *, transparent=None, **kwargs):
patch.set_facecolor('none')
patch.set_edgecolor('none')
else:
kwargs.setdefault('facecolor', rcParams['savefig.facecolor'])
kwargs.setdefault('edgecolor', rcParams['savefig.edgecolor'])
kwargs.setdefault('facecolor', mpl.rcParams['savefig.facecolor'])
kwargs.setdefault('edgecolor', mpl.rcParams['savefig.edgecolor'])

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

Expand Down Expand Up @@ -2734,7 +2734,7 @@ def figaspect(arg):
arr_ratio = arg

# Height of user figure defaults
fig_height = rcParams['figure.figsize'][1]
fig_height = mpl.rcParams['figure.figsize'][1]

# New size for the figure, keeping the aspect ratio of the caller
newsize = np.array((fig_height / arr_ratio, fig_height))
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/sankey.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import numpy as np

import matplotlib as mpl
from matplotlib.path import Path
from matplotlib.patches import PathPatch
from matplotlib.transforms import Affine2D
from matplotlib import docstring
from matplotlib import rcParams

_log = logging.getLogger(__name__)

Expand Down Expand Up @@ -718,7 +718,7 @@ def _get_angle(a, r):
vertices = translate(rotate(vertices))
kwds = dict(s=patchlabel, ha='center', va='center')
text = self.ax.text(*offset, **kwds)
if rcParams['_internal.classic_mode']:
if mpl.rcParams['_internal.classic_mode']:
fc = kwargs.pop('fc', kwargs.pop('facecolor', '#bfd1d4'))
lw = kwargs.pop('lw', kwargs.pop('linewidth', 0.5))
else:
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/tests/test_backend_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import matplotlib
from matplotlib import pyplot as plt
from matplotlib import rcParams
from matplotlib._pylab_helpers import Gcf

import pytest
Expand Down Expand Up @@ -246,8 +245,8 @@ def test_double_resize():

w, h = 3, 2
fig.set_size_inches(w, h)
assert fig.canvas.width() == w * rcParams['figure.dpi']
assert fig.canvas.height() == h * rcParams['figure.dpi']
assert fig.canvas.width() == w * matplotlib.rcParams['figure.dpi']
assert fig.canvas.height() == h * matplotlib.rcParams['figure.dpi']

old_width = window.width()
old_height = window.height()
Expand Down