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

Skip to content

Commit a68784f

Browse files
committed
Change manual kwargs popping to kwonly arguments.
Only simple cases (no mutable defaults, no defaults depending on other args) are handled so far.
1 parent 640ecd9 commit a68784f

37 files changed

Lines changed: 199 additions & 304 deletions

examples/api/radar_chart.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ def __init__(self, *args, **kwargs):
6464
# rotate plot such that the first axis is at the top
6565
self.set_theta_zero_location('N')
6666

67-
def fill(self, *args, **kwargs):
67+
def fill(self, *args, closed=True, **kwargs):
6868
"""Override fill so that line is closed by default"""
69-
closed = kwargs.pop('closed', True)
7069
return super().fill(closed=closed, *args, **kwargs)
7170

7271
def plot(self, *args, **kwargs):

examples/images_contours_and_fields/contour_demo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@
9898
plt.setp(zc, linewidth=4)
9999

100100
ax.clabel(CS, levels[1::2], # label every second level
101-
inline=1, fmt='%1.1f',
102-
cmap='flag', fontsize=14)
101+
inline=1, fmt='%1.1f', fontsize=14)
103102

104103
# make a colorbar for the contour lines
105104
CB = fig.colorbar(CS, shrink=0.8, extend='both')

examples/scales/custom_scale.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MercatorLatitudeScale(mscale.ScaleBase):
4444
# scale.
4545
name = 'mercator'
4646

47-
def __init__(self, axis, **kwargs):
47+
def __init__(self, axis, *, thresh=np.deg2rad(85), **kwargs):
4848
"""
4949
Any keyword arguments passed to ``set_xscale`` and
5050
``set_yscale`` will be passed along to the scale's
@@ -53,8 +53,7 @@ def __init__(self, axis, **kwargs):
5353
thresh: The degree above which to crop the data.
5454
"""
5555
mscale.ScaleBase.__init__(self)
56-
thresh = kwargs.pop("thresh", np.radians(85))
57-
if thresh >= np.pi / 2.0:
56+
if thresh >= np.pi / 2:
5857
raise ValueError("thresh must be less than pi/2")
5958
self.thresh = thresh
6059

examples/subplots_axes_and_figures/custom_figure_class.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212

1313

1414
class MyFigure(Figure):
15-
def __init__(self, *args, **kwargs):
15+
def __init__(self, *args, figtitle='hi mom', **kwargs):
1616
"""
1717
custom kwarg figtitle is a figure title
1818
"""
19-
figtitle = kwargs.pop('figtitle', 'hi mom')
20-
Figure.__init__(self, *args, **kwargs)
19+
super().__init__(*args, **kwargs)
2120
self.text(0.5, 0.95, figtitle, ha='center')
2221

2322

examples/text_labels_and_annotations/usetex_baseline_test.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,15 @@ class Axes(maxes.Axes):
2020
usetex=False in the same figure. It does not work in the ps backend.
2121
"""
2222

23-
def __init__(self, *kl, **kw):
24-
self.usetex = kw.pop("usetex", "False")
25-
self.preview = kw.pop("preview", "False")
26-
27-
maxes.Axes.__init__(self, *kl, **kw)
23+
def __init__(self, *args, usetex=False, preview=False, **kwargs):
24+
self.usetex = usetex
25+
self.preview = preview
26+
super().__init__(*args, **kwargs)
2827

2928
def draw(self, renderer):
30-
usetex = plt.rcParams["text.usetex"]
31-
preview = plt.rcParams["text.latex.preview"]
32-
plt.rcParams["text.usetex"] = self.usetex
33-
plt.rcParams["text.latex.preview"] = self.preview
34-
35-
maxes.Axes.draw(self, renderer)
36-
37-
plt.rcParams["text.usetex"] = usetex
38-
plt.rcParams["text.latex.preview"] = preview
29+
with plt.rc_context({"text.usetex": self.usetex,
30+
"text.latex.preview": self.preview}):
31+
super().draw(renderer)
3932

4033

4134
subplot = maxes.subplot_class_factory(Axes)

examples/user_interfaces/toolmanager_sgskip.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class GroupHideTool(ToolToggleBase):
5656
description = 'Show by gid'
5757
default_toggled = True
5858

59-
def __init__(self, *args, **kwargs):
60-
self.gid = kwargs.pop('gid')
61-
ToolToggleBase.__init__(self, *args, **kwargs)
59+
def __init__(self, *args, gid, **kwargs):
60+
self.gid = gid
61+
super().__init__(*args, **kwargs)
6262

6363
def enable(self, *args):
6464
self.set_lines_visibility(True)

lib/matplotlib/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,7 @@ def param(func):
17031703
pass
17041704

17051705
@functools.wraps(func)
1706-
def inner(ax, *args, **kwargs):
1706+
def inner(ax, *args, data=None, **kwargs):
17071707
# this is needed because we want to change these values if
17081708
# arg_names_at_runtime==True, but python does not allow assigning
17091709
# to a variable in a outer scope. So use some new local ones and
@@ -1714,8 +1714,6 @@ def inner(ax, *args, **kwargs):
17141714

17151715
label = None
17161716

1717-
data = kwargs.pop('data', None)
1718-
17191717
if data is None: # data validation
17201718
args = tuple(sanitize_sequence(a) for a in args)
17211719
else:

lib/matplotlib/axes/_axes.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5243,20 +5243,14 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
52435243
return im
52445244

52455245
@staticmethod
5246-
def _pcolorargs(funcname, *args, **kw):
5247-
# This takes one kwarg, allmatch.
5248-
# If allmatch is True, then the incoming X, Y, C must
5249-
# have matching dimensions, taking into account that
5250-
# X and Y can be 1-D rather than 2-D. This perfect
5251-
# match is required for Gouroud shading. For flat
5252-
# shading, X and Y specify boundaries, so we need
5253-
# one more boundary than color in each direction.
5254-
# For convenience, and consistent with Matlab, we
5255-
# discard the last row and/or column of C if necessary
5256-
# to meet this condition. This is done if allmatch
5257-
# is False.
5258-
5259-
allmatch = kw.pop("allmatch", False)
5246+
def _pcolorargs(funcname, *args, allmatch=False):
5247+
# If allmatch is True, then the incoming X, Y, C must have matching
5248+
# dimensions, taking into account that X and Y can be 1-D rather than
5249+
# 2-D. This perfect match is required for Gouroud shading. For flat
5250+
# shading, X and Y specify boundaries, so we need one more boundary
5251+
# than color in each direction. For convenience, and consistent with
5252+
# Matlab, we discard the last row and/or column of C if necessary to
5253+
# meet this condition. This is done if allmatch is False.
52605254

52615255
if len(args) == 1:
52625256
C = np.asanyarray(args[0])
@@ -5303,7 +5297,7 @@ def _pcolorargs(funcname, *args, **kw):
53035297
'Incompatible X, Y inputs to %s; see help(%s)' % (
53045298
funcname, funcname))
53055299
if allmatch:
5306-
if not (Nx == numCols and Ny == numRows):
5300+
if (Nx, Ny) != (numCols, numRows):
53075301
raise TypeError('Dimensions of C %s are incompatible with'
53085302
' X (%d) and/or Y (%d); see help(%s)' % (
53095303
C.shape, Nx, Ny, funcname))

lib/matplotlib/axes/_base.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,8 @@ def grid(self, b=None, which='major', axis='both', **kwargs):
26832683
if axis == 'y' or axis == 'both':
26842684
self.yaxis.grid(b, which=which, **kwargs)
26852685

2686-
def ticklabel_format(self, **kwargs):
2686+
def ticklabel_format(self, *, axis='both', style='', scilimits=None,
2687+
useOffset=None, useLocale=None, useMathText=None):
26872688
"""
26882689
Change the `~matplotlib.ticker.ScalarFormatter` used by
26892690
default for linear axes.
@@ -2693,6 +2694,7 @@ def ticklabel_format(self, **kwargs):
26932694
============== =========================================
26942695
Keyword Description
26952696
============== =========================================
2697+
*axis* [ 'x' | 'y' | 'both' ]
26962698
*style* [ 'sci' (or 'scientific') | 'plain' ]
26972699
plain turns off scientific notation
26982700
*scilimits* (m, n), pair of integers; if *style*
@@ -2705,7 +2707,6 @@ def ticklabel_format(self, **kwargs):
27052707
if False, no offset will be used; if a
27062708
numeric offset is specified, it will be
27072709
used.
2708-
*axis* [ 'x' | 'y' | 'both' ]
27092710
*useLocale* If True, format the number according to
27102711
the current locale. This affects things
27112712
such as the character used for the
@@ -2724,12 +2725,8 @@ def ticklabel_format(self, **kwargs):
27242725
:exc:`AttributeError` will be raised.
27252726
27262727
"""
2727-
style = kwargs.pop('style', '').lower()
2728-
scilimits = kwargs.pop('scilimits', None)
2729-
useOffset = kwargs.pop('useOffset', None)
2730-
useLocale = kwargs.pop('useLocale', None)
2731-
useMathText = kwargs.pop('useMathText', None)
2732-
axis = kwargs.pop('axis', 'both').lower()
2728+
style = style.lower()
2729+
axis = axis.lower()
27332730
if scilimits is not None:
27342731
try:
27352732
m, n = scilimits

lib/matplotlib/axis.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ def set_pickradius(self, pickradius):
16161616
"""
16171617
self.pickradius = pickradius
16181618

1619-
def set_ticklabels(self, ticklabels, *args, **kwargs):
1619+
def set_ticklabels(self, ticklabels, *args, minor=False, **kwargs):
16201620
"""
16211621
Set the text values of the tick labels. Return a list of Text
16221622
instances. Use *kwarg* *minor=True* to select minor ticks.
@@ -1645,7 +1645,6 @@ def set_ticklabels(self, ticklabels, *args, **kwargs):
16451645
# replace the ticklabels list with the processed one
16461646
ticklabels = get_labels
16471647

1648-
minor = kwargs.pop('minor', False)
16491648
if minor:
16501649
self.set_minor_formatter(mticker.FixedFormatter(ticklabels))
16511650
ticks = self.get_minor_ticks()

0 commit comments

Comments
 (0)