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

Skip to content

Commit 33c243a

Browse files
committed
Don't import rcParams but rather use mpl.rcParams (part 2)
1 parent d9ae387 commit 33c243a

13 files changed

+168
-159
lines changed

lib/matplotlib/artist.py

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

99
import numpy as np
1010

11-
import matplotlib
12-
from . import cbook, docstring, rcParams
11+
import matplotlib as mpl
12+
from . import cbook, docstring
1313
from .path import Path
1414
from .transforms import (Bbox, IdentityTransform, Transform, TransformedBbox,
1515
TransformedPatchPath, TransformedPath)
@@ -99,8 +99,8 @@ def __init__(self):
9999
self._url = None
100100
self._gid = None
101101
self._snap = None
102-
self._sketch = rcParams['path.sketch']
103-
self._path_effects = rcParams['path.effects']
102+
self._sketch = mpl.rcParams['path.sketch']
103+
self._path_effects = mpl.rcParams['path.effects']
104104
self._sticky_edges = _XYPair([], [])
105105
self._in_layout = True
106106

@@ -588,7 +588,7 @@ def get_snap(self):
588588
589589
See `.set_snap` for details.
590590
"""
591-
if rcParams['path.snap']:
591+
if mpl.rcParams['path.snap']:
592592
return self._snap
593593
else:
594594
return False
@@ -1602,7 +1602,7 @@ def kwdoc(artist):
16021602
"""
16031603
ai = ArtistInspector(artist)
16041604
return ('\n'.join(ai.pprint_setters_rest(leadingspace=4))
1605-
if matplotlib.rcParams['docstring.hardcopy'] else
1605+
if mpl.rcParams['docstring.hardcopy'] else
16061606
'Properties:\n' + '\n'.join(ai.pprint_setters(leadingspace=4)))
16071607

16081608

lib/matplotlib/axis.py

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import numpy as np
99

10-
from matplotlib import rcParams
10+
import matplotlib as mpl
1111
import matplotlib.artist as martist
1212
import matplotlib.cbook as cbook
1313
import matplotlib.lines as mlines
@@ -84,11 +84,12 @@ def __init__(self, axes, loc, label=None,
8484
martist.Artist.__init__(self)
8585

8686
if gridOn is None:
87-
if major and (rcParams['axes.grid.which'] in ('both', 'major')):
88-
gridOn = rcParams['axes.grid']
89-
elif (not major) and (rcParams['axes.grid.which']
87+
if major and (mpl.rcParams['axes.grid.which']
88+
in ('both', 'major')):
89+
gridOn = mpl.rcParams['axes.grid']
90+
elif (not major) and (mpl.rcParams['axes.grid.which']
9091
in ('both', 'minor')):
91-
gridOn = rcParams['axes.grid']
92+
gridOn = mpl.rcParams['axes.grid']
9293
else:
9394
gridOn = False
9495

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

104105
if size is None:
105-
size = rcParams[f"{name}.{major_minor}.size"]
106+
size = mpl.rcParams[f"{name}.{major_minor}.size"]
106107
self._size = size
107108

108109
if width is None:
109-
width = rcParams[f"{name}.{major_minor}.width"]
110+
width = mpl.rcParams[f"{name}.{major_minor}.width"]
110111
self._width = width
111112

112113
if color is None:
113-
color = rcParams[f"{name}.color"]
114+
color = mpl.rcParams[f"{name}.color"]
114115

115116
if pad is None:
116-
pad = rcParams[f"{name}.{major_minor}.pad"]
117+
pad = mpl.rcParams[f"{name}.{major_minor}.pad"]
117118
self._base_pad = pad
118119

119120
if labelcolor is None:
120-
labelcolor = rcParams[f"{name}.color"]
121+
labelcolor = mpl.rcParams[f"{name}.color"]
121122

122123
if labelsize is None:
123-
labelsize = rcParams[f"{name}.labelsize"]
124+
labelsize = mpl.rcParams[f"{name}.labelsize"]
124125

125126
self._set_labelrotation(labelrotation)
126127

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

134135
if grid_color is None:
135-
grid_color = rcParams["grid.color"]
136+
grid_color = mpl.rcParams["grid.color"]
136137
if grid_linestyle is None:
137-
grid_linestyle = rcParams["grid.linestyle"]
138+
grid_linestyle = mpl.rcParams["grid.linestyle"]
138139
if grid_linewidth is None:
139-
grid_linewidth = rcParams["grid.linewidth"]
140+
grid_linewidth = mpl.rcParams["grid.linewidth"]
140141
if grid_alpha is None:
141-
grid_alpha = rcParams["grid.alpha"]
142+
grid_alpha = mpl.rcParams["grid.alpha"]
142143
grid_kw = {k[5:]: v for k, v in kw.items()}
143144

144145
self.apply_tickdir(tickdir)
@@ -453,7 +454,7 @@ def _get_text2_transform(self):
453454

454455
def apply_tickdir(self, tickdir):
455456
if tickdir is None:
456-
tickdir = rcParams['%s.direction' % self.__name__.lower()]
457+
tickdir = mpl.rcParams['%s.direction' % self.__name__.lower()]
457458
self._tickdir = tickdir
458459

459460
if self._tickdir == 'in':
@@ -524,7 +525,7 @@ def _get_text2_transform(self):
524525

525526
def apply_tickdir(self, tickdir):
526527
if tickdir is None:
527-
tickdir = rcParams['%s.direction' % self.__name__.lower()]
528+
tickdir = mpl.rcParams['%s.direction' % self.__name__.lower()]
528529
self._tickdir = tickdir
529530

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

690691
self.label = mtext.Text(
691692
np.nan, np.nan,
692-
fontsize=rcParams['axes.labelsize'],
693-
fontweight=rcParams['axes.labelweight'],
694-
color=rcParams['axes.labelcolor'],
693+
fontsize=mpl.rcParams['axes.labelsize'],
694+
fontweight=mpl.rcParams['axes.labelweight'],
695+
color=mpl.rcParams['axes.labelcolor'],
695696
)
696697
self._set_artist_props(self.label)
697698
self.offsetText = mtext.Text(np.nan, np.nan)
698699
self._set_artist_props(self.offsetText)
699700

700-
self.labelpad = rcParams['axes.labelpad']
701+
self.labelpad = mpl.rcParams['axes.labelpad']
701702

702703
self.pickradius = pickradius
703704

@@ -778,10 +779,12 @@ def cla(self):
778779
self.callbacks = cbook.CallbackRegistry()
779780

780781
# whether the grids are on
781-
self._gridOnMajor = (rcParams['axes.grid'] and
782-
rcParams['axes.grid.which'] in ('both', 'major'))
783-
self._gridOnMinor = (rcParams['axes.grid'] and
784-
rcParams['axes.grid.which'] in ('both', 'minor'))
782+
self._gridOnMajor = (
783+
mpl.rcParams['axes.grid'] and
784+
mpl.rcParams['axes.grid.which'] in ('both', 'major'))
785+
self._gridOnMinor = (
786+
mpl.rcParams['axes.grid'] and
787+
mpl.rcParams['axes.grid.which'] in ('both', 'minor'))
785788

786789
self.reset_ticks()
787790

@@ -1842,8 +1845,8 @@ def __init__(self, *args, **kwargs):
18421845
verticalalignment='top', horizontalalignment='right',
18431846
transform=mtransforms.blended_transform_factory(
18441847
self.axes.transAxes, mtransforms.IdentityTransform()),
1845-
fontsize=rcParams['xtick.labelsize'],
1846-
color=rcParams['xtick.color'],
1848+
fontsize=mpl.rcParams['xtick.labelsize'],
1849+
color=mpl.rcParams['xtick.color'],
18471850
)
18481851
self.offset_text_position = 'bottom'
18491852

@@ -2135,8 +2138,8 @@ def __init__(self, *args, **kwargs):
21352138
verticalalignment='baseline', horizontalalignment='left',
21362139
transform=mtransforms.blended_transform_factory(
21372140
self.axes.transAxes, mtransforms.IdentityTransform()),
2138-
fontsize=rcParams['ytick.labelsize'],
2139-
color=rcParams['ytick.color'],
2141+
fontsize=mpl.rcParams['ytick.labelsize'],
2142+
color=mpl.rcParams['ytick.color'],
21402143
)
21412144
self.offset_text_position = 'left'
21422145

lib/matplotlib/backend_tools.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import numpy as np
2222

23-
from matplotlib import rcParams
23+
import matplotlib as mpl
2424
from matplotlib._pylab_helpers import Gcf
2525
import matplotlib.cbook as cbook
2626

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

396396
description = 'Quit the figure'
397-
default_keymap = rcParams['keymap.quit']
397+
default_keymap = mpl.rcParams['keymap.quit']
398398

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

406406
description = 'Quit all figures'
407-
default_keymap = rcParams['keymap.quit_all']
407+
default_keymap = mpl.rcParams['keymap.quit_all']
408408

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

416416
description = 'Enable all axes toolmanager'
417-
default_keymap = rcParams['keymap.all_axes']
417+
default_keymap = mpl.rcParams['keymap.all_axes']
418418

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

484484
description = 'Toggle major grids'
485-
default_keymap = rcParams['keymap.grid']
485+
default_keymap = mpl.rcParams['keymap.grid']
486486

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

505505
description = 'Toggle major and minor grids'
506-
default_keymap = rcParams['keymap.grid_minor']
506+
default_keymap = mpl.rcParams['keymap.grid_minor']
507507

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

525525
description = 'Toggle fullscreen mode'
526-
default_keymap = rcParams['keymap.fullscreen']
526+
default_keymap = mpl.rcParams['keymap.fullscreen']
527527

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

555555
description = 'Toggle scale Y axis'
556-
default_keymap = rcParams['keymap.yscale']
556+
default_keymap = mpl.rcParams['keymap.yscale']
557557

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

565565
description = 'Toggle scale X axis'
566-
default_keymap = rcParams['keymap.xscale']
566+
default_keymap = mpl.rcParams['keymap.xscale']
567567

568568
def set_scale(self, ax, scale):
569569
ax.set_xscale(scale)
@@ -738,7 +738,7 @@ class ToolHome(ViewsPositionsBase):
738738

739739
description = 'Reset original view'
740740
image = 'home'
741-
default_keymap = rcParams['keymap.home']
741+
default_keymap = mpl.rcParams['keymap.home']
742742
_on_trigger = 'home'
743743

744744

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

748748
description = 'Back to previous view'
749749
image = 'back'
750-
default_keymap = rcParams['keymap.back']
750+
default_keymap = mpl.rcParams['keymap.back']
751751
_on_trigger = 'back'
752752

753753

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

757757
description = 'Forward to next view'
758758
image = 'forward'
759-
default_keymap = rcParams['keymap.forward']
759+
default_keymap = mpl.rcParams['keymap.forward']
760760
_on_trigger = 'forward'
761761

762762

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

773773
description = 'Save the figure'
774774
image = 'filesave'
775-
default_keymap = rcParams['keymap.save']
775+
default_keymap = mpl.rcParams['keymap.save']
776776

777777

778778
class ZoomPanBase(ToolToggleBase):
@@ -844,7 +844,7 @@ class ToolZoom(ZoomPanBase):
844844

845845
description = 'Zoom to rectangle'
846846
image = 'zoom_to_rect'
847-
default_keymap = rcParams['keymap.zoom']
847+
default_keymap = mpl.rcParams['keymap.zoom']
848848
cursor = cursors.SELECT_REGION
849849
radio_group = 'default'
850850

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

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

10341034
class ToolHelpBase(ToolBase):
10351035
description = 'Print tool list, shortcuts and description'
1036-
default_keymap = rcParams['keymap.help']
1036+
default_keymap = mpl.rcParams['keymap.help']
10371037
image = 'help.png'
10381038

10391039
@staticmethod
@@ -1073,7 +1073,7 @@ class ToolCopyToClipboardBase(ToolBase):
10731073
"""Tool to copy the figure to the clipboard"""
10741074

10751075
description = 'Copy the canvas figure to clipboard'
1076-
default_keymap = rcParams['keymap.copy']
1076+
default_keymap = mpl.rcParams['keymap.copy']
10771077

10781078
def trigger(self, *args, **kwargs):
10791079
message = "Copy tool is not available"

0 commit comments

Comments
 (0)