Skip to content

Don't import rcParams but rather use mpl.rcParams (part 2) #16525

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
Feb 16, 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
12 changes: 6 additions & 6 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import numpy as np

import matplotlib
from . import cbook, docstring, rcParams
import matplotlib as mpl
from . import cbook, docstring
from .path import Path
from .transforms import (Bbox, IdentityTransform, Transform, TransformedBbox,
TransformedPatchPath, TransformedPath)
Expand Down Expand Up @@ -99,8 +99,8 @@ def __init__(self):
self._url = None
self._gid = None
self._snap = None
self._sketch = rcParams['path.sketch']
self._path_effects = rcParams['path.effects']
self._sketch = mpl.rcParams['path.sketch']
self._path_effects = mpl.rcParams['path.effects']
self._sticky_edges = _XYPair([], [])
self._in_layout = True

Expand Down Expand Up @@ -588,7 +588,7 @@ def get_snap(self):

See `.set_snap` for details.
"""
if rcParams['path.snap']:
if mpl.rcParams['path.snap']:
return self._snap
else:
return False
Expand Down Expand Up @@ -1602,7 +1602,7 @@ def kwdoc(artist):
"""
ai = ArtistInspector(artist)
return ('\n'.join(ai.pprint_setters_rest(leadingspace=4))
if matplotlib.rcParams['docstring.hardcopy'] else
if mpl.rcParams['docstring.hardcopy'] else
'Properties:\n' + '\n'.join(ai.pprint_setters(leadingspace=4)))


Expand Down
61 changes: 32 additions & 29 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import numpy as np

from matplotlib import rcParams
import matplotlib as mpl
import matplotlib.artist as martist
import matplotlib.cbook as cbook
import matplotlib.lines as mlines
Expand Down Expand Up @@ -84,11 +84,12 @@ def __init__(self, axes, loc, label=None,
martist.Artist.__init__(self)

if gridOn is None:
if major and (rcParams['axes.grid.which'] in ('both', 'major')):
gridOn = rcParams['axes.grid']
elif (not major) and (rcParams['axes.grid.which']
if major and (mpl.rcParams['axes.grid.which']
in ('both', 'major')):
gridOn = mpl.rcParams['axes.grid']
elif (not major) and (mpl.rcParams['axes.grid.which']
in ('both', 'minor')):
gridOn = rcParams['axes.grid']
gridOn = mpl.rcParams['axes.grid']
else:
gridOn = False

Expand All @@ -102,25 +103,25 @@ def __init__(self, axes, loc, label=None,
major_minor = "major" if major else "minor"

if size is None:
size = rcParams[f"{name}.{major_minor}.size"]
size = mpl.rcParams[f"{name}.{major_minor}.size"]
self._size = size

if width is None:
width = rcParams[f"{name}.{major_minor}.width"]
width = mpl.rcParams[f"{name}.{major_minor}.width"]
self._width = width

if color is None:
color = rcParams[f"{name}.color"]
color = mpl.rcParams[f"{name}.color"]

if pad is None:
pad = rcParams[f"{name}.{major_minor}.pad"]
pad = mpl.rcParams[f"{name}.{major_minor}.pad"]
self._base_pad = pad

if labelcolor is None:
labelcolor = rcParams[f"{name}.color"]
labelcolor = mpl.rcParams[f"{name}.color"]

if labelsize is None:
labelsize = rcParams[f"{name}.labelsize"]
labelsize = mpl.rcParams[f"{name}.labelsize"]

self._set_labelrotation(labelrotation)

Expand All @@ -132,13 +133,13 @@ def __init__(self, axes, loc, label=None,
self._zorder = zorder

if grid_color is None:
grid_color = rcParams["grid.color"]
grid_color = mpl.rcParams["grid.color"]
if grid_linestyle is None:
grid_linestyle = rcParams["grid.linestyle"]
grid_linestyle = mpl.rcParams["grid.linestyle"]
if grid_linewidth is None:
grid_linewidth = rcParams["grid.linewidth"]
grid_linewidth = mpl.rcParams["grid.linewidth"]
if grid_alpha is None:
grid_alpha = rcParams["grid.alpha"]
grid_alpha = mpl.rcParams["grid.alpha"]
grid_kw = {k[5:]: v for k, v in kw.items()}

self.apply_tickdir(tickdir)
Expand Down Expand Up @@ -453,7 +454,7 @@ def _get_text2_transform(self):

def apply_tickdir(self, tickdir):
if tickdir is None:
tickdir = rcParams['%s.direction' % self.__name__.lower()]
tickdir = mpl.rcParams['%s.direction' % self.__name__.lower()]
self._tickdir = tickdir

if self._tickdir == 'in':
Expand Down Expand Up @@ -524,7 +525,7 @@ def _get_text2_transform(self):

def apply_tickdir(self, tickdir):
if tickdir is None:
tickdir = rcParams['%s.direction' % self.__name__.lower()]
tickdir = mpl.rcParams['%s.direction' % self.__name__.lower()]
self._tickdir = tickdir

if self._tickdir == 'in':
Expand Down Expand Up @@ -689,15 +690,15 @@ def __init__(self, axes, pickradius=15):

self.label = mtext.Text(
np.nan, np.nan,
fontsize=rcParams['axes.labelsize'],
fontweight=rcParams['axes.labelweight'],
color=rcParams['axes.labelcolor'],
fontsize=mpl.rcParams['axes.labelsize'],
fontweight=mpl.rcParams['axes.labelweight'],
color=mpl.rcParams['axes.labelcolor'],
)
self._set_artist_props(self.label)
self.offsetText = mtext.Text(np.nan, np.nan)
self._set_artist_props(self.offsetText)

self.labelpad = rcParams['axes.labelpad']
self.labelpad = mpl.rcParams['axes.labelpad']

self.pickradius = pickradius

Expand Down Expand Up @@ -778,10 +779,12 @@ def cla(self):
self.callbacks = cbook.CallbackRegistry()

# whether the grids are on
self._gridOnMajor = (rcParams['axes.grid'] and
rcParams['axes.grid.which'] in ('both', 'major'))
self._gridOnMinor = (rcParams['axes.grid'] and
rcParams['axes.grid.which'] in ('both', 'minor'))
self._gridOnMajor = (
mpl.rcParams['axes.grid'] and
mpl.rcParams['axes.grid.which'] in ('both', 'major'))
self._gridOnMinor = (
mpl.rcParams['axes.grid'] and
mpl.rcParams['axes.grid.which'] in ('both', 'minor'))

self.reset_ticks()

Expand Down Expand Up @@ -1842,8 +1845,8 @@ def __init__(self, *args, **kwargs):
verticalalignment='top', horizontalalignment='right',
transform=mtransforms.blended_transform_factory(
self.axes.transAxes, mtransforms.IdentityTransform()),
fontsize=rcParams['xtick.labelsize'],
color=rcParams['xtick.color'],
fontsize=mpl.rcParams['xtick.labelsize'],
color=mpl.rcParams['xtick.color'],
)
self.offset_text_position = 'bottom'

Expand Down Expand Up @@ -2135,8 +2138,8 @@ def __init__(self, *args, **kwargs):
verticalalignment='baseline', horizontalalignment='left',
transform=mtransforms.blended_transform_factory(
self.axes.transAxes, mtransforms.IdentityTransform()),
fontsize=rcParams['ytick.labelsize'],
color=rcParams['ytick.color'],
fontsize=mpl.rcParams['ytick.labelsize'],
color=mpl.rcParams['ytick.color'],
)
self.offset_text_position = 'left'

Expand Down
34 changes: 17 additions & 17 deletions lib/matplotlib/backend_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import numpy as np

from matplotlib import rcParams
import matplotlib as mpl
from matplotlib._pylab_helpers import Gcf
import matplotlib.cbook as cbook

Expand Down Expand Up @@ -394,7 +394,7 @@ class ToolQuit(ToolBase):
"""Tool to call the figure manager destroy method"""

description = 'Quit the figure'
default_keymap = rcParams['keymap.quit']
default_keymap = mpl.rcParams['keymap.quit']

def trigger(self, sender, event, data=None):
Gcf.destroy_fig(self.figure)
Expand All @@ -404,7 +404,7 @@ class ToolQuitAll(ToolBase):
"""Tool to call the figure manager destroy method"""

description = 'Quit all figures'
default_keymap = rcParams['keymap.quit_all']
default_keymap = mpl.rcParams['keymap.quit_all']

def trigger(self, sender, event, data=None):
Gcf.destroy_all()
Expand All @@ -414,7 +414,7 @@ class ToolEnableAllNavigation(ToolBase):
"""Tool to enable all axes for toolmanager interaction"""

description = 'Enable all axes toolmanager'
default_keymap = rcParams['keymap.all_axes']
default_keymap = mpl.rcParams['keymap.all_axes']

def trigger(self, sender, event, data=None):
if event.inaxes is None:
Expand Down Expand Up @@ -482,7 +482,7 @@ class ToolGrid(_ToolGridBase):
"""Tool to toggle the major grids of the figure"""

description = 'Toggle major grids'
default_keymap = rcParams['keymap.grid']
default_keymap = mpl.rcParams['keymap.grid']

def _get_next_grid_states(self, ax):
if None in map(self._get_uniform_grid_state,
Expand All @@ -503,7 +503,7 @@ class ToolMinorGrid(_ToolGridBase):
"""Tool to toggle the major and minor grids of the figure"""

description = 'Toggle major and minor grids'
default_keymap = rcParams['keymap.grid_minor']
default_keymap = mpl.rcParams['keymap.grid_minor']

def _get_next_grid_states(self, ax):
if None in map(self._get_uniform_grid_state,
Expand All @@ -523,7 +523,7 @@ class ToolFullScreen(ToolToggleBase):
"""Tool to toggle full screen"""

description = 'Toggle fullscreen mode'
default_keymap = rcParams['keymap.fullscreen']
default_keymap = mpl.rcParams['keymap.fullscreen']

def enable(self, event):
self.figure.canvas.manager.full_screen_toggle()
Expand Down Expand Up @@ -553,7 +553,7 @@ class ToolYScale(AxisScaleBase):
"""Tool to toggle between linear and logarithmic scales on the Y axis"""

description = 'Toggle scale Y axis'
default_keymap = rcParams['keymap.yscale']
default_keymap = mpl.rcParams['keymap.yscale']

def set_scale(self, ax, scale):
ax.set_yscale(scale)
Expand All @@ -563,7 +563,7 @@ class ToolXScale(AxisScaleBase):
"""Tool to toggle between linear and logarithmic scales on the X axis"""

description = 'Toggle scale X axis'
default_keymap = rcParams['keymap.xscale']
default_keymap = mpl.rcParams['keymap.xscale']

def set_scale(self, ax, scale):
ax.set_xscale(scale)
Expand Down Expand Up @@ -738,7 +738,7 @@ class ToolHome(ViewsPositionsBase):

description = 'Reset original view'
image = 'home'
default_keymap = rcParams['keymap.home']
default_keymap = mpl.rcParams['keymap.home']
_on_trigger = 'home'


Expand All @@ -747,7 +747,7 @@ class ToolBack(ViewsPositionsBase):

description = 'Back to previous view'
image = 'back'
default_keymap = rcParams['keymap.back']
default_keymap = mpl.rcParams['keymap.back']
_on_trigger = 'back'


Expand All @@ -756,7 +756,7 @@ class ToolForward(ViewsPositionsBase):

description = 'Forward to next view'
image = 'forward'
default_keymap = rcParams['keymap.forward']
default_keymap = mpl.rcParams['keymap.forward']
_on_trigger = 'forward'


Expand All @@ -772,7 +772,7 @@ class SaveFigureBase(ToolBase):

description = 'Save the figure'
image = 'filesave'
default_keymap = rcParams['keymap.save']
default_keymap = mpl.rcParams['keymap.save']


class ZoomPanBase(ToolToggleBase):
Expand Down Expand Up @@ -844,7 +844,7 @@ class ToolZoom(ZoomPanBase):

description = 'Zoom to rectangle'
image = 'zoom_to_rect'
default_keymap = rcParams['keymap.zoom']
default_keymap = mpl.rcParams['keymap.zoom']
cursor = cursors.SELECT_REGION
radio_group = 'default'

Expand Down Expand Up @@ -968,7 +968,7 @@ def _release(self, event):
class ToolPan(ZoomPanBase):
"""Pan axes with left mouse, zoom with right"""

default_keymap = rcParams['keymap.pan']
default_keymap = mpl.rcParams['keymap.pan']
description = 'Pan axes with left mouse, zoom with right'
image = 'move'
cursor = cursors.MOVE
Expand Down Expand Up @@ -1033,7 +1033,7 @@ def _mouse_move(self, event):

class ToolHelpBase(ToolBase):
description = 'Print tool list, shortcuts and description'
default_keymap = rcParams['keymap.help']
default_keymap = mpl.rcParams['keymap.help']
image = 'help.png'

@staticmethod
Expand Down Expand Up @@ -1073,7 +1073,7 @@ class ToolCopyToClipboardBase(ToolBase):
"""Tool to copy the figure to the clipboard"""

description = 'Copy the canvas figure to clipboard'
default_keymap = rcParams['keymap.copy']
default_keymap = mpl.rcParams['keymap.copy']

def trigger(self, *args, **kwargs):
message = "Copy tool is not available"
Expand Down
Loading