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

Skip to content

Commit 67e1814

Browse files
committed
Rename **kw to **kwargs.
... and small local cleanups.
1 parent 1daed58 commit 67e1814

File tree

10 files changed

+106
-107
lines changed

10 files changed

+106
-107
lines changed

lib/matplotlib/axis.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,29 @@ class Tick(martist.Artist):
5454
The right/top tick label.
5555
5656
"""
57-
def __init__(self, axes, loc, *,
58-
size=None, # points
59-
width=None,
60-
color=None,
61-
tickdir=None,
62-
pad=None,
63-
labelsize=None,
64-
labelcolor=None,
65-
zorder=None,
66-
gridOn=None, # defaults to axes.grid depending on
67-
# axes.grid.which
68-
tick1On=True,
69-
tick2On=True,
70-
label1On=True,
71-
label2On=False,
72-
major=True,
73-
labelrotation=0,
74-
grid_color=None,
75-
grid_linestyle=None,
76-
grid_linewidth=None,
77-
grid_alpha=None,
78-
**kw # Other Line2D kwargs applied to gridlines.
79-
):
57+
def __init__(
58+
self, axes, loc, *,
59+
size=None, # points
60+
width=None,
61+
color=None,
62+
tickdir=None,
63+
pad=None,
64+
labelsize=None,
65+
labelcolor=None,
66+
zorder=None,
67+
gridOn=None, # defaults to axes.grid depending on axes.grid.which
68+
tick1On=True,
69+
tick2On=True,
70+
label1On=True,
71+
label2On=False,
72+
major=True,
73+
labelrotation=0,
74+
grid_color=None,
75+
grid_linestyle=None,
76+
grid_linewidth=None,
77+
grid_alpha=None,
78+
**kwargs, # Other Line2D kwargs applied to gridlines.
79+
):
8080
"""
8181
bbox is the Bound2D bounding box in display coords of the Axes
8282
loc is the tick location in data coords
@@ -145,7 +145,7 @@ def __init__(self, axes, loc, *,
145145
grid_linewidth = mpl.rcParams["grid.linewidth"]
146146
if grid_alpha is None:
147147
grid_alpha = mpl.rcParams["grid.alpha"]
148-
grid_kw = {k[5:]: v for k, v in kw.items()}
148+
grid_kw = {k[5:]: v for k, v in kwargs.items()}
149149

150150
self.tick1line = mlines.Line2D(
151151
[], [],
@@ -346,23 +346,23 @@ def get_view_interval(self):
346346
"""
347347
raise NotImplementedError('Derived must override')
348348

349-
def _apply_params(self, **kw):
349+
def _apply_params(self, **kwargs):
350350
for name, target in [("gridOn", self.gridline),
351351
("tick1On", self.tick1line),
352352
("tick2On", self.tick2line),
353353
("label1On", self.label1),
354354
("label2On", self.label2)]:
355-
if name in kw:
356-
target.set_visible(kw.pop(name))
357-
if any(k in kw for k in ['size', 'width', 'pad', 'tickdir']):
358-
self._size = kw.pop('size', self._size)
355+
if name in kwargs:
356+
target.set_visible(kwargs.pop(name))
357+
if any(k in kwargs for k in ['size', 'width', 'pad', 'tickdir']):
358+
self._size = kwargs.pop('size', self._size)
359359
# Width could be handled outside this block, but it is
360360
# convenient to leave it here.
361-
self._width = kw.pop('width', self._width)
362-
self._base_pad = kw.pop('pad', self._base_pad)
361+
self._width = kwargs.pop('width', self._width)
362+
self._base_pad = kwargs.pop('pad', self._base_pad)
363363
# _apply_tickdir uses _size and _base_pad to make _pad, and also
364364
# sets the ticklines markers.
365-
self._apply_tickdir(kw.pop('tickdir', self._tickdir))
365+
self._apply_tickdir(kwargs.pop('tickdir', self._tickdir))
366366
for line in (self.tick1line, self.tick2line):
367367
line.set_markersize(self._size)
368368
line.set_markeredgewidth(self._width)
@@ -371,25 +371,25 @@ def _apply_params(self, **kw):
371371
self.label1.set_transform(trans)
372372
trans = self._get_text2_transform()[0]
373373
self.label2.set_transform(trans)
374-
tick_kw = {k: v for k, v in kw.items() if k in ['color', 'zorder']}
375-
if 'color' in kw:
376-
tick_kw['markeredgecolor'] = kw['color']
374+
tick_kw = {k: v for k, v in kwargs.items() if k in ['color', 'zorder']}
375+
if 'color' in kwargs:
376+
tick_kw['markeredgecolor'] = kwargs['color']
377377
self.tick1line.set(**tick_kw)
378378
self.tick2line.set(**tick_kw)
379379
for k, v in tick_kw.items():
380380
setattr(self, '_' + k, v)
381381

382-
if 'labelrotation' in kw:
383-
self._set_labelrotation(kw.pop('labelrotation'))
382+
if 'labelrotation' in kwargs:
383+
self._set_labelrotation(kwargs.pop('labelrotation'))
384384
self.label1.set(rotation=self._labelrotation[1])
385385
self.label2.set(rotation=self._labelrotation[1])
386386

387-
label_kw = {k[5:]: v for k, v in kw.items()
387+
label_kw = {k[5:]: v for k, v in kwargs.items()
388388
if k in ['labelsize', 'labelcolor']}
389389
self.label1.set(**label_kw)
390390
self.label2.set(**label_kw)
391391

392-
grid_kw = {k[5:]: v for k, v in kw.items()
392+
grid_kw = {k[5:]: v for k, v in kwargs.items()
393393
if k in _gridline_param_names}
394394
self.gridline.set(**grid_kw)
395395

@@ -847,15 +847,15 @@ def reset_ticks(self):
847847
except AttributeError:
848848
pass
849849

850-
def set_tick_params(self, which='major', reset=False, **kw):
850+
def set_tick_params(self, which='major', reset=False, **kwargs):
851851
"""
852852
Set appearance parameters for ticks, ticklabels, and gridlines.
853853
854854
For documentation of keyword arguments, see
855855
:meth:`matplotlib.axes.Axes.tick_params`.
856856
"""
857857
_api.check_in_list(['major', 'minor', 'both'], which=which)
858-
kwtrans = self._translate_tick_kw(kw)
858+
kwtrans = self._translate_tick_kw(kwargs)
859859

860860
# the kwargs are stored in self._major/minor_tick_kw so that any
861861
# future new ticks will automatically get them

lib/matplotlib/colorbar.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class __getattr__:
204204
lambda self: _make_axes_param_doc + _make_axes_other_param_doc))
205205

206206

207-
def _set_ticks_on_axis_warn(*args, **kw):
207+
def _set_ticks_on_axis_warn(*args, **kwargs):
208208
# a top level function which gets put in at the axes'
209209
# set_xticks and set_yticks by Colorbar.__init__.
210210
_api.warn_external("Use the colorbar set_ticks() method instead.")
@@ -1355,7 +1355,7 @@ def _normalize_location_orientation(location, orientation):
13551355

13561356
@docstring.Substitution(_make_axes_param_doc, _make_axes_other_param_doc)
13571357
def make_axes(parents, location=None, orientation=None, fraction=0.15,
1358-
shrink=1.0, aspect=20, **kw):
1358+
shrink=1.0, aspect=20, **kwargs):
13591359
"""
13601360
Create an `~.axes.Axes` suitable for a colorbar.
13611361
@@ -1372,7 +1372,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
13721372
-------
13731373
cax : `~.axes.Axes`
13741374
The child axes.
1375-
kw : dict
1375+
kwargs : dict
13761376
The reduced keyword dictionary to be passed when creating the colorbar
13771377
instance.
13781378
@@ -1381,13 +1381,13 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
13811381
%s
13821382
"""
13831383
loc_settings = _normalize_location_orientation(location, orientation)
1384-
# put appropriate values into the kw dict for passing back to
1384+
# put appropriate values into the kwargs dict for passing back to
13851385
# the Colorbar class
1386-
kw['orientation'] = loc_settings['orientation']
1387-
location = kw['ticklocation'] = loc_settings['location']
1386+
kwargs['orientation'] = loc_settings['orientation']
1387+
location = kwargs['ticklocation'] = loc_settings['location']
13881388

1389-
anchor = kw.pop('anchor', loc_settings['anchor'])
1390-
panchor = kw.pop('panchor', loc_settings['panchor'])
1389+
anchor = kwargs.pop('anchor', loc_settings['anchor'])
1390+
panchor = kwargs.pop('panchor', loc_settings['panchor'])
13911391
aspect0 = aspect
13921392
# turn parents into a list if it is not already. We do this w/ np
13931393
# because `plt.subplots` can return an ndarray and is natural to
@@ -1396,7 +1396,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
13961396
fig = parents[0].get_figure()
13971397

13981398
pad0 = 0.05 if fig.get_constrained_layout() else loc_settings['pad']
1399-
pad = kw.pop('pad', pad0)
1399+
pad = kwargs.pop('pad', pad0)
14001400

14011401
if not all(fig is ax.get_figure() for ax in parents):
14021402
raise ValueError('Unable to create a colorbar axes as not all '
@@ -1453,12 +1453,12 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
14531453
cax.set_box_aspect(aspect)
14541454
cax.set_aspect('auto')
14551455

1456-
return cax, kw
1456+
return cax, kwargs
14571457

14581458

14591459
@docstring.Substitution(_make_axes_param_doc, _make_axes_other_param_doc)
14601460
def make_axes_gridspec(parent, *, location=None, orientation=None,
1461-
fraction=0.15, shrink=1.0, aspect=20, **kw):
1461+
fraction=0.15, shrink=1.0, aspect=20, **kwargs):
14621462
"""
14631463
Create a `.SubplotBase` suitable for a colorbar.
14641464
@@ -1488,7 +1488,7 @@ def make_axes_gridspec(parent, *, location=None, orientation=None,
14881488
-------
14891489
cax : `~.axes.SubplotBase`
14901490
The child axes.
1491-
kw : dict
1491+
kwargs : dict
14921492
The reduced keyword dictionary to be passed when creating the colorbar
14931493
instance.
14941494
@@ -1498,13 +1498,13 @@ def make_axes_gridspec(parent, *, location=None, orientation=None,
14981498
"""
14991499

15001500
loc_settings = _normalize_location_orientation(location, orientation)
1501-
kw['orientation'] = loc_settings['orientation']
1502-
location = kw['ticklocation'] = loc_settings['location']
1501+
kwargs['orientation'] = loc_settings['orientation']
1502+
location = kwargs['ticklocation'] = loc_settings['location']
15031503

15041504
aspect0 = aspect
1505-
anchor = kw.pop('anchor', loc_settings['anchor'])
1506-
panchor = kw.pop('panchor', loc_settings['panchor'])
1507-
pad = kw.pop('pad', loc_settings["pad"])
1505+
anchor = kwargs.pop('anchor', loc_settings['anchor'])
1506+
panchor = kwargs.pop('panchor', loc_settings['panchor'])
1507+
pad = kwargs.pop('pad', loc_settings["pad"])
15081508
wh_space = 2 * pad / (1 - pad)
15091509

15101510
if location in ('left', 'right'):
@@ -1565,7 +1565,7 @@ def make_axes_gridspec(parent, *, location=None, orientation=None,
15651565
fraction=fraction,
15661566
aspect=aspect0,
15671567
pad=pad)
1568-
return cax, kw
1568+
return cax, kwargs
15691569

15701570

15711571
@_api.deprecated("3.4", alternative="Colorbar")

lib/matplotlib/figure.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,8 @@ def text(self, x, y, s, fontdict=None, **kwargs):
11271127
return text
11281128

11291129
@docstring.dedent_interpd
1130-
def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
1130+
def colorbar(
1131+
self, mappable, cax=None, ax=None, use_gridspec=True, **kwargs):
11311132
"""%(colorbar_doc)s"""
11321133
if ax is None:
11331134
ax = self.gca()
@@ -1146,16 +1147,16 @@ def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
11461147
userax = False
11471148
if (use_gridspec and isinstance(ax, SubplotBase)
11481149
and not self.get_constrained_layout()):
1149-
cax, kw = cbar.make_axes_gridspec(ax, **kw)
1150+
cax, kwargs = cbar.make_axes_gridspec(ax, **kwargs)
11501151
else:
1151-
cax, kw = cbar.make_axes(ax, **kw)
1152+
cax, kwargs = cbar.make_axes(ax, **kwargs)
11521153
else:
11531154
userax = True
11541155

11551156
# need to remove kws that cannot be passed to Colorbar
11561157
NON_COLORBAR_KEYS = ['fraction', 'pad', 'shrink', 'aspect', 'anchor',
11571158
'panchor']
1158-
cb_kw = {k: v for k, v in kw.items() if k not in NON_COLORBAR_KEYS}
1159+
cb_kw = {k: v for k, v in kwargs.items() if k not in NON_COLORBAR_KEYS}
11591160

11601161
cb = cbar.Colorbar(cax, mappable, **cb_kw)
11611162

lib/matplotlib/patches.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,7 +2128,7 @@ class _Style:
21282128
where actual styles are declared as subclass of it, and it
21292129
provides some helper functions.
21302130
"""
2131-
def __new__(cls, stylename, **kw):
2131+
def __new__(cls, stylename, **kwargs):
21322132
"""Return the instance of the subclass with the given style name."""
21332133

21342134
# The "class" should have the _style_list attribute, which is a mapping
@@ -2147,7 +2147,7 @@ def __new__(cls, stylename, **kw):
21472147
except ValueError as err:
21482148
raise ValueError("Incorrect style argument : %s" %
21492149
stylename) from err
2150-
_args.update(kw)
2150+
_args.update(kwargs)
21512151

21522152
return _cls(**_args)
21532153

@@ -4329,7 +4329,7 @@ def set_patchB(self, patchB):
43294329
self.patchB = patchB
43304330
self.stale = True
43314331

4332-
def set_connectionstyle(self, connectionstyle, **kw):
4332+
def set_connectionstyle(self, connectionstyle, **kwargs):
43334333
"""
43344334
Set the connection style. Old attributes are forgotten.
43354335
@@ -4356,14 +4356,14 @@ def set_connectionstyle(self, connectionstyle, **kw):
43564356
callable(connectionstyle)):
43574357
self._connector = connectionstyle
43584358
else:
4359-
self._connector = ConnectionStyle(connectionstyle, **kw)
4359+
self._connector = ConnectionStyle(connectionstyle, **kwargs)
43604360
self.stale = True
43614361

43624362
def get_connectionstyle(self):
43634363
"""Return the `ConnectionStyle` used."""
43644364
return self._connector
43654365

4366-
def set_arrowstyle(self, arrowstyle=None, **kw):
4366+
def set_arrowstyle(self, arrowstyle=None, **kwargs):
43674367
"""
43684368
Set the arrow style. Old attributes are forgotten. Without arguments
43694369
(or with ``arrowstyle=None``) returns available box styles as a list of
@@ -4389,7 +4389,7 @@ def set_arrowstyle(self, arrowstyle=None, **kw):
43894389
if isinstance(arrowstyle, ArrowStyle._Base):
43904390
self._arrow_transmuter = arrowstyle
43914391
else:
4392-
self._arrow_transmuter = ArrowStyle(arrowstyle, **kw)
4392+
self._arrow_transmuter = ArrowStyle(arrowstyle, **kwargs)
43934393
self.stale = True
43944394

43954395
def get_arrowstyle(self):

lib/matplotlib/projections/polar.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,8 @@ def __init__(self, axes, *args, **kwargs):
284284
rotation_mode='anchor',
285285
transform=self.label2.get_transform() + self._text2_translate)
286286

287-
def _apply_params(self, **kw):
288-
super()._apply_params(**kw)
289-
287+
def _apply_params(self, **kwargs):
288+
super()._apply_params(**kwargs)
290289
# Ensure transform is correct; sometimes this gets reset.
291290
trans = self.label1.get_transform()
292291
if not trans.contains_branch(self._text1_translate):

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,15 +2073,15 @@ def _setup_pyplot_info_docstrings():
20732073

20742074

20752075
@_copy_docstring_and_deprecators(Figure.colorbar)
2076-
def colorbar(mappable=None, cax=None, ax=None, **kw):
2076+
def colorbar(mappable=None, cax=None, ax=None, **kwargs):
20772077
if mappable is None:
20782078
mappable = gci()
20792079
if mappable is None:
20802080
raise RuntimeError('No mappable was found to use for colorbar '
20812081
'creation. First define a mappable such as '
20822082
'an image (with imshow) or a contour set ('
20832083
'with contourf).')
2084-
ret = gcf().colorbar(mappable, cax=cax, ax=ax, **kw)
2084+
ret = gcf().colorbar(mappable, cax=cax, ax=ax, **kwargs)
20852085
return ret
20862086

20872087

0 commit comments

Comments
 (0)