Skip to content

Rename **kw to **kwargs. #21152

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
Sep 22, 2021
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
82 changes: 41 additions & 41 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,29 @@ class Tick(martist.Artist):
The right/top tick label.

"""
def __init__(self, axes, loc, *,
size=None, # points
width=None,
color=None,
tickdir=None,
pad=None,
labelsize=None,
labelcolor=None,
zorder=None,
gridOn=None, # defaults to axes.grid depending on
# axes.grid.which
tick1On=True,
tick2On=True,
label1On=True,
label2On=False,
major=True,
labelrotation=0,
grid_color=None,
grid_linestyle=None,
grid_linewidth=None,
grid_alpha=None,
**kw # Other Line2D kwargs applied to gridlines.
):
def __init__(
self, axes, loc, *,
size=None, # points
width=None,
color=None,
tickdir=None,
pad=None,
labelsize=None,
labelcolor=None,
zorder=None,
gridOn=None, # defaults to axes.grid depending on axes.grid.which
tick1On=True,
tick2On=True,
label1On=True,
label2On=False,
major=True,
labelrotation=0,
grid_color=None,
grid_linestyle=None,
grid_linewidth=None,
grid_alpha=None,
**kwargs, # Other Line2D kwargs applied to gridlines.
):
"""
bbox is the Bound2D bounding box in display coords of the Axes
loc is the tick location in data coords
Expand Down Expand Up @@ -145,7 +145,7 @@ def __init__(self, axes, loc, *,
grid_linewidth = mpl.rcParams["grid.linewidth"]
if grid_alpha is None:
grid_alpha = mpl.rcParams["grid.alpha"]
grid_kw = {k[5:]: v for k, v in kw.items()}
grid_kw = {k[5:]: v for k, v in kwargs.items()}

self.tick1line = mlines.Line2D(
[], [],
Expand Down Expand Up @@ -346,23 +346,23 @@ def get_view_interval(self):
"""
raise NotImplementedError('Derived must override')

def _apply_params(self, **kw):
def _apply_params(self, **kwargs):
for name, target in [("gridOn", self.gridline),
("tick1On", self.tick1line),
("tick2On", self.tick2line),
("label1On", self.label1),
("label2On", self.label2)]:
if name in kw:
target.set_visible(kw.pop(name))
if any(k in kw for k in ['size', 'width', 'pad', 'tickdir']):
self._size = kw.pop('size', self._size)
if name in kwargs:
target.set_visible(kwargs.pop(name))
if any(k in kwargs for k in ['size', 'width', 'pad', 'tickdir']):
self._size = kwargs.pop('size', self._size)
# Width could be handled outside this block, but it is
# convenient to leave it here.
self._width = kw.pop('width', self._width)
self._base_pad = kw.pop('pad', self._base_pad)
self._width = kwargs.pop('width', self._width)
self._base_pad = kwargs.pop('pad', self._base_pad)
# _apply_tickdir uses _size and _base_pad to make _pad, and also
# sets the ticklines markers.
self._apply_tickdir(kw.pop('tickdir', self._tickdir))
self._apply_tickdir(kwargs.pop('tickdir', self._tickdir))
for line in (self.tick1line, self.tick2line):
line.set_markersize(self._size)
line.set_markeredgewidth(self._width)
Expand All @@ -371,25 +371,25 @@ def _apply_params(self, **kw):
self.label1.set_transform(trans)
trans = self._get_text2_transform()[0]
self.label2.set_transform(trans)
tick_kw = {k: v for k, v in kw.items() if k in ['color', 'zorder']}
if 'color' in kw:
tick_kw['markeredgecolor'] = kw['color']
tick_kw = {k: v for k, v in kwargs.items() if k in ['color', 'zorder']}
if 'color' in kwargs:
tick_kw['markeredgecolor'] = kwargs['color']
self.tick1line.set(**tick_kw)
self.tick2line.set(**tick_kw)
for k, v in tick_kw.items():
setattr(self, '_' + k, v)

if 'labelrotation' in kw:
self._set_labelrotation(kw.pop('labelrotation'))
if 'labelrotation' in kwargs:
self._set_labelrotation(kwargs.pop('labelrotation'))
self.label1.set(rotation=self._labelrotation[1])
self.label2.set(rotation=self._labelrotation[1])

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

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

Expand Down Expand Up @@ -847,15 +847,15 @@ def reset_ticks(self):
except AttributeError:
pass

def set_tick_params(self, which='major', reset=False, **kw):
def set_tick_params(self, which='major', reset=False, **kwargs):
"""
Set appearance parameters for ticks, ticklabels, and gridlines.

For documentation of keyword arguments, see
:meth:`matplotlib.axes.Axes.tick_params`.
"""
_api.check_in_list(['major', 'minor', 'both'], which=which)
kwtrans = self._translate_tick_kw(kw)
kwtrans = self._translate_tick_kw(kwargs)

# the kwargs are stored in self._major/minor_tick_kw so that any
# future new ticks will automatically get them
Expand Down
36 changes: 18 additions & 18 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class __getattr__:
lambda self: _make_axes_param_doc + _make_axes_other_param_doc))


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

@docstring.Substitution(_make_axes_param_doc, _make_axes_other_param_doc)
def make_axes(parents, location=None, orientation=None, fraction=0.15,
shrink=1.0, aspect=20, **kw):
shrink=1.0, aspect=20, **kwargs):
"""
Create an `~.axes.Axes` suitable for a colorbar.

Expand All @@ -1372,7 +1372,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
-------
cax : `~.axes.Axes`
The child axes.
kw : dict
kwargs : dict
The reduced keyword dictionary to be passed when creating the colorbar
instance.

Expand All @@ -1381,13 +1381,13 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
%s
"""
loc_settings = _normalize_location_orientation(location, orientation)
# put appropriate values into the kw dict for passing back to
# put appropriate values into the kwargs dict for passing back to
# the Colorbar class
kw['orientation'] = loc_settings['orientation']
location = kw['ticklocation'] = loc_settings['location']
kwargs['orientation'] = loc_settings['orientation']
location = kwargs['ticklocation'] = loc_settings['location']

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

pad0 = 0.05 if fig.get_constrained_layout() else loc_settings['pad']
pad = kw.pop('pad', pad0)
pad = kwargs.pop('pad', pad0)

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

return cax, kw
return cax, kwargs


@docstring.Substitution(_make_axes_param_doc, _make_axes_other_param_doc)
def make_axes_gridspec(parent, *, location=None, orientation=None,
fraction=0.15, shrink=1.0, aspect=20, **kw):
fraction=0.15, shrink=1.0, aspect=20, **kwargs):
"""
Create a `.SubplotBase` suitable for a colorbar.

Expand Down Expand Up @@ -1488,7 +1488,7 @@ def make_axes_gridspec(parent, *, location=None, orientation=None,
-------
cax : `~.axes.SubplotBase`
The child axes.
kw : dict
kwargs : dict
The reduced keyword dictionary to be passed when creating the colorbar
instance.

Expand All @@ -1498,13 +1498,13 @@ def make_axes_gridspec(parent, *, location=None, orientation=None,
"""

loc_settings = _normalize_location_orientation(location, orientation)
kw['orientation'] = loc_settings['orientation']
location = kw['ticklocation'] = loc_settings['location']
kwargs['orientation'] = loc_settings['orientation']
location = kwargs['ticklocation'] = loc_settings['location']

aspect0 = aspect
anchor = kw.pop('anchor', loc_settings['anchor'])
panchor = kw.pop('panchor', loc_settings['panchor'])
pad = kw.pop('pad', loc_settings["pad"])
anchor = kwargs.pop('anchor', loc_settings['anchor'])
panchor = kwargs.pop('panchor', loc_settings['panchor'])
pad = kwargs.pop('pad', loc_settings["pad"])
wh_space = 2 * pad / (1 - pad)

if location in ('left', 'right'):
Expand Down Expand Up @@ -1565,7 +1565,7 @@ def make_axes_gridspec(parent, *, location=None, orientation=None,
fraction=fraction,
aspect=aspect0,
pad=pad)
return cax, kw
return cax, kwargs


@_api.deprecated("3.4", alternative="Colorbar")
Expand Down
9 changes: 5 additions & 4 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,8 @@ def text(self, x, y, s, fontdict=None, **kwargs):
return text

@docstring.dedent_interpd
def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
def colorbar(
self, mappable, cax=None, ax=None, use_gridspec=True, **kwargs):
"""%(colorbar_doc)s"""
if ax is None:
ax = self.gca()
Expand All @@ -1146,16 +1147,16 @@ def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
userax = False
if (use_gridspec and isinstance(ax, SubplotBase)
and not self.get_constrained_layout()):
cax, kw = cbar.make_axes_gridspec(ax, **kw)
cax, kwargs = cbar.make_axes_gridspec(ax, **kwargs)
else:
cax, kw = cbar.make_axes(ax, **kw)
cax, kwargs = cbar.make_axes(ax, **kwargs)
else:
userax = True

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

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

Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2128,7 +2128,7 @@ class _Style:
where actual styles are declared as subclass of it, and it
provides some helper functions.
"""
def __new__(cls, stylename, **kw):
def __new__(cls, stylename, **kwargs):
"""Return the instance of the subclass with the given style name."""

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

return _cls(**_args)

Expand Down Expand Up @@ -4329,7 +4329,7 @@ def set_patchB(self, patchB):
self.patchB = patchB
self.stale = True

def set_connectionstyle(self, connectionstyle, **kw):
def set_connectionstyle(self, connectionstyle, **kwargs):
"""
Set the connection style. Old attributes are forgotten.

Expand All @@ -4356,14 +4356,14 @@ def set_connectionstyle(self, connectionstyle, **kw):
callable(connectionstyle)):
self._connector = connectionstyle
else:
self._connector = ConnectionStyle(connectionstyle, **kw)
self._connector = ConnectionStyle(connectionstyle, **kwargs)
self.stale = True

def get_connectionstyle(self):
"""Return the `ConnectionStyle` used."""
return self._connector

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

def get_arrowstyle(self):
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/projections/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,8 @@ def __init__(self, axes, *args, **kwargs):
rotation_mode='anchor',
transform=self.label2.get_transform() + self._text2_translate)

def _apply_params(self, **kw):
super()._apply_params(**kw)

def _apply_params(self, **kwargs):
super()._apply_params(**kwargs)
# Ensure transform is correct; sometimes this gets reset.
trans = self.label1.get_transform()
if not trans.contains_branch(self._text1_translate):
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2073,15 +2073,15 @@ def _setup_pyplot_info_docstrings():


@_copy_docstring_and_deprecators(Figure.colorbar)
def colorbar(mappable=None, cax=None, ax=None, **kw):
def colorbar(mappable=None, cax=None, ax=None, **kwargs):
if mappable is None:
mappable = gci()
if mappable is None:
raise RuntimeError('No mappable was found to use for colorbar '
'creation. First define a mappable such as '
'an image (with imshow) or a contour set ('
'with contourf).')
ret = gcf().colorbar(mappable, cax=cax, ax=ax, **kw)
ret = gcf().colorbar(mappable, cax=cax, ax=ax, **kwargs)
return ret


Expand Down
Loading