Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1fc7891

Browse files
committed
Change manual kwargs popping to kwonly arguments.
Only simple cases (no mutable defaults, no defaults depending on otherargs) are handled so far.
1 parentb1f5c43 commit1fc7891

37 files changed

+200
-310
lines changed

‎examples/api/custom_scale_example.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-
ifthresh>=np.pi/2.0:
56+
ifthresh>=np.pi/2:
5857
raiseValueError("thresh must be less than pi/2")
5958
self.thresh=thresh
6059

‎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-
deffill(self,*args,**kwargs):
67+
deffill(self,*args,closed=True,**kwargs):
6868
"""Override fill so that line is closed by default"""
69-
closed=kwargs.pop('closed',True)
7069
returnsuper().fill(closed=closed,*args,**kwargs)
7170

7271
defplot(self,*args,**kwargs):

‎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
classMyFigure(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
defdraw(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+
withplt.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
defenable(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
@@ -1692,7 +1692,7 @@ def param(func):
16921692
pass
16931693

16941694
@functools.wraps(func)
1695-
definner(ax,*args,**kwargs):
1695+
definner(ax,*args,data=None,**kwargs):
16961696
# this is needed because we want to change these values if
16971697
# arg_names_at_runtime==True, but python does not allow assigning
16981698
# to a variable in a outer scope. So use some new local ones and
@@ -1703,8 +1703,6 @@ def inner(ax, *args, **kwargs):
17031703

17041704
label=None
17051705

1706-
data=kwargs.pop('data',None)
1707-
17081706
ifdataisNone:# data validation
17091707
args=tuple(sanitize_sequence(a)forainargs)
17101708
else:

‎lib/matplotlib/axes/_axes.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5489,20 +5489,14 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
54895489
returnim
54905490

54915491
@staticmethod
5492-
def_pcolorargs(funcname,*args,**kw):
5493-
# This takes one kwarg, allmatch.
5494-
# If allmatch is True, then the incoming X, Y, C must
5495-
# have matching dimensions, taking into account that
5496-
# X and Y can be 1-D rather than 2-D. This perfect
5497-
# match is required for Gouroud shading. For flat
5498-
# shading, X and Y specify boundaries, so we need
5499-
# one more boundary than color in each direction.
5500-
# For convenience, and consistent with Matlab, we
5501-
# discard the last row and/or column of C if necessary
5502-
# to meet this condition. This is done if allmatch
5503-
# is False.
5504-
5505-
allmatch=kw.pop("allmatch",False)
5492+
def_pcolorargs(funcname,*args,allmatch=False):
5493+
# If allmatch is True, then the incoming X, Y, C must have matching
5494+
# dimensions, taking into account that X and Y can be 1-D rather than
5495+
# 2-D. This perfect match is required for Gouroud shading. For flat
5496+
# shading, X and Y specify boundaries, so we need one more boundary
5497+
# than color in each direction. For convenience, and consistent with
5498+
# Matlab, we discard the last row and/or column of C if necessary to
5499+
# meet this condition. This is done if allmatch is False.
55065500

55075501
iflen(args)==1:
55085502
C=np.asanyarray(args[0])
@@ -5549,7 +5543,7 @@ def _pcolorargs(funcname, *args, **kw):
55495543
'Incompatible X, Y inputs to %s; see help(%s)'% (
55505544
funcname,funcname))
55515545
ifallmatch:
5552-
ifnot(Nx==numColsandNy==numRows):
5546+
if (Nx,Ny)!= (numCols,numRows):
55535547
raiseTypeError('Dimensions of C %s are incompatible with'
55545548
' X (%d) and/or Y (%d); see help(%s)'% (
55555549
C.shape,Nx,Ny,funcname))

‎lib/matplotlib/axes/_base.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,7 +2688,8 @@ def grid(self, b=None, which='major', axis='both', **kwargs):
26882688
ifaxis=='y'oraxis=='both':
26892689
self.yaxis.grid(b,which=which,**kwargs)
26902690

2691-
defticklabel_format(self,**kwargs):
2691+
defticklabel_format(self,*,axis='both',style='',scilimits=None,
2692+
useOffset=None,useLocale=None,useMathText=None):
26922693
"""
26932694
Change the `~matplotlib.ticker.ScalarFormatter` used by
26942695
default for linear axes.
@@ -2698,6 +2699,7 @@ def ticklabel_format(self, **kwargs):
26982699
============== =========================================
26992700
Keyword Description
27002701
============== =========================================
2702+
*axis* [ 'x' | 'y' | 'both' ]
27012703
*style* [ 'sci' (or 'scientific') | 'plain' ]
27022704
plain turns off scientific notation
27032705
*scilimits* (m, n), pair of integers; if *style*
@@ -2710,7 +2712,6 @@ def ticklabel_format(self, **kwargs):
27102712
if False, no offset will be used; if a
27112713
numeric offset is specified, it will be
27122714
used.
2713-
*axis* [ 'x' | 'y' | 'both' ]
27142715
*useLocale* If True, format the number according to
27152716
the current locale. This affects things
27162717
such as the character used for the
@@ -2729,12 +2730,8 @@ def ticklabel_format(self, **kwargs):
27292730
:exc:`AttributeError` will be raised.
27302731
27312732
"""
2732-
style=kwargs.pop('style','').lower()
2733-
scilimits=kwargs.pop('scilimits',None)
2734-
useOffset=kwargs.pop('useOffset',None)
2735-
useLocale=kwargs.pop('useLocale',None)
2736-
useMathText=kwargs.pop('useMathText',None)
2737-
axis=kwargs.pop('axis','both').lower()
2733+
style=style.lower()
2734+
axis=axis.lower()
27382735
ifscilimitsisnotNone:
27392736
try:
27402737
m,n=scilimits

‎lib/matplotlib/axis.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,7 @@ def set_pickradius(self, pickradius):
16261626
"""
16271627
self.pickradius=pickradius
16281628

1629-
defset_ticklabels(self,ticklabels,*args,**kwargs):
1629+
defset_ticklabels(self,ticklabels,*args,minor=False,**kwargs):
16301630
"""
16311631
Set the text values of the tick labels. Return a list of Text
16321632
instances. Use *kwarg* *minor=True* to select minor ticks.
@@ -1655,7 +1655,6 @@ def set_ticklabels(self, ticklabels, *args, **kwargs):
16551655
# replace the ticklabels list with the processed one
16561656
ticklabels=get_labels
16571657

1658-
minor=kwargs.pop('minor',False)
16591658
ifminor:
16601659
self.set_minor_formatter(mticker.FixedFormatter(ticklabels))
16611660
ticks=self.get_minor_ticks()

‎lib/matplotlib/backends/backend_agg.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def print_to_buffer(self):
536536

537537
if_has_pil:
538538
# add JPEG support
539-
defprint_jpg(self,filename_or_obj,*args,**kwargs):
539+
defprint_jpg(self,filename_or_obj,*args,dryrun=False,**kwargs):
540540
"""
541541
Other Parameters
542542
----------------
@@ -557,7 +557,7 @@ def print_jpg(self, filename_or_obj, *args, **kwargs):
557557
should be stored as a progressive JPEG file.
558558
"""
559559
buf,size=self.print_to_buffer()
560-
ifkwargs.pop("dryrun",False):
560+
ifdryrun:
561561
return
562562
# The image is "pasted" onto a white background image to safely
563563
# handle any transparency
@@ -578,9 +578,9 @@ def print_jpg(self, filename_or_obj, *args, **kwargs):
578578
print_jpeg=print_jpg
579579

580580
# add TIFF support
581-
defprint_tif(self,filename_or_obj,*args,**kwargs):
581+
defprint_tif(self,filename_or_obj,*args,dryrun=False,**kwargs):
582582
buf,size=self.print_to_buffer()
583-
ifkwargs.pop("dryrun",False):
583+
ifdryrun:
584584
return
585585
image=Image.frombuffer('RGBA',size,buf,'raw','RGBA',0,1)
586586
dpi= (self.figure.dpi,self.figure.dpi)

‎lib/matplotlib/backends/backend_pdf.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,21 +2562,22 @@ def draw(self):
25622562
defget_default_filetype(self):
25632563
return'pdf'
25642564

2565-
defprint_pdf(self,filename,**kwargs):
2566-
image_dpi=kwargs.get('dpi',72)# dpi to use for images
2565+
defprint_pdf(self,filename,*,
2566+
dpi=72,# dpi to use for images
2567+
bbox_inches_restore=None,metadata=None,
2568+
**kwargs):
25672569
self.figure.set_dpi(72)# there are 72 pdf points to an inch
25682570
width,height=self.figure.get_size_inches()
25692571
ifisinstance(filename,PdfPages):
25702572
file=filename._file
25712573
else:
2572-
file=PdfFile(filename,metadata=kwargs.pop("metadata",None))
2574+
file=PdfFile(filename,metadata=metadata)
25732575
try:
25742576
file.newPage(width,height)
2575-
_bbox_inches_restore=kwargs.pop("bbox_inches_restore",None)
25762577
renderer=MixedModeRenderer(
2577-
self.figure,width,height,image_dpi,
2578-
RendererPdf(file,image_dpi,height,width),
2579-
bbox_inches_restore=_bbox_inches_restore)
2578+
self.figure,width,height,dpi,
2579+
RendererPdf(file,dpi,height,width),
2580+
bbox_inches_restore=bbox_inches_restore)
25802581
self.figure.draw(renderer)
25812582
renderer.finalize()
25822583
ifnotisinstance(filename,PdfPages):

‎lib/matplotlib/backends/backend_pgf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,9 @@ class FigureCanvasPgf(FigureCanvasBase):
802802
defget_default_filetype(self):
803803
return'pdf'
804804

805-
def_print_pgf_to_fh(self,fh,*args,**kwargs):
806-
ifkwargs.get("dryrun",False):
805+
def_print_pgf_to_fh(self,fh,*args,
806+
dryrun=False,bbox_inches_restore=None,**kwargs):
807+
ifdryrun:
807808
renderer=RendererPgf(self.figure,None,dummy=True)
808809
self.figure.draw(renderer)
809810
return
@@ -849,10 +850,9 @@ def _print_pgf_to_fh(self, fh, *args, **kwargs):
849850
r"\pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{%fin}{%fin}}"
850851
% (w,h))
851852
writeln(fh,r"\pgfusepath{use as bounding box, clip}")
852-
_bbox_inches_restore=kwargs.pop("bbox_inches_restore",None)
853853
renderer=MixedModeRenderer(self.figure,w,h,dpi,
854854
RendererPgf(self.figure,fh),
855-
bbox_inches_restore=_bbox_inches_restore)
855+
bbox_inches_restore=bbox_inches_restore)
856856
self.figure.draw(renderer)
857857

858858
# end the pgfpicture environment

‎lib/matplotlib/backends/backend_ps.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -957,9 +957,11 @@ def _print_ps(self, outfile, format, *args, **kwargs):
957957
orientation,isLandscape,papertype,
958958
**kwargs)
959959

960-
def_print_figure(self,outfile,format,dpi=72,facecolor='w',edgecolor='w',
961-
orientation='portrait',isLandscape=False,papertype=None,
962-
metadata=None,**kwargs):
960+
def_print_figure(
961+
self,outfile,format,dpi=72,facecolor='w',edgecolor='w',
962+
orientation='portrait',isLandscape=False,papertype=None,
963+
metadata=None,*,
964+
dryrun=False,bbox_inches_restore=None,**kwargs):
963965
"""
964966
Render the figure to hardcopy. Set the figure patch face and
965967
edge colors. This is useful because some of the GUIs have a
@@ -1029,8 +1031,6 @@ def _print_figure(self, outfile, format, dpi=72, facecolor='w', edgecolor='w',
10291031
self.figure.set_facecolor(facecolor)
10301032
self.figure.set_edgecolor(edgecolor)
10311033

1032-
1033-
dryrun=kwargs.get("dryrun",False)
10341034
ifdryrun:
10351035
classNullWriter(object):
10361036
defwrite(self,*kl,**kwargs):
@@ -1040,14 +1040,12 @@ def write(self, *kl, **kwargs):
10401040
else:
10411041
self._pswriter=io.StringIO()
10421042

1043-
10441043
# mixed mode rendering
1045-
_bbox_inches_restore=kwargs.pop("bbox_inches_restore",None)
10461044
ps_renderer=self._renderer_class(width,height,self._pswriter,
10471045
imagedpi=dpi)
10481046
renderer=MixedModeRenderer(self.figure,
10491047
width,height,dpi,ps_renderer,
1050-
bbox_inches_restore=_bbox_inches_restore)
1048+
bbox_inches_restore=bbox_inches_restore)
10511049

10521050
self.figure.draw(renderer)
10531051

@@ -1197,9 +1195,10 @@ def do_nothing():
11971195
withio.open(outfile,'w',encoding='latin-1')asfh:
11981196
print_figure_impl(fh)
11991197

1200-
def_print_figure_tex(self,outfile,format,dpi,facecolor,edgecolor,
1201-
orientation,isLandscape,papertype,metadata=None,
1202-
**kwargs):
1198+
def_print_figure_tex(
1199+
self,outfile,format,dpi,facecolor,edgecolor,
1200+
orientation,isLandscape,papertype,metadata=None,*,
1201+
dryrun=False,bbox_inches_restore=None,**kwargs):
12031202
"""
12041203
If text.usetex is True in rc, a temporary pair of tex/eps files
12051204
are created to allow tex to manage the text layout via the PSFrags
@@ -1234,7 +1233,6 @@ def _print_figure_tex(self, outfile, format, dpi, facecolor, edgecolor,
12341233
self.figure.set_facecolor(facecolor)
12351234
self.figure.set_edgecolor(edgecolor)
12361235

1237-
dryrun=kwargs.get("dryrun",False)
12381236
ifdryrun:
12391237
classNullWriter(object):
12401238
defwrite(self,*kl,**kwargs):
@@ -1245,12 +1243,11 @@ def write(self, *kl, **kwargs):
12451243
self._pswriter=io.StringIO()
12461244

12471245
# mixed mode rendering
1248-
_bbox_inches_restore=kwargs.pop("bbox_inches_restore",None)
12491246
ps_renderer=self._renderer_class(width,height,
12501247
self._pswriter,imagedpi=dpi)
12511248
renderer=MixedModeRenderer(self.figure,
12521249
width,height,dpi,ps_renderer,
1253-
bbox_inches_restore=_bbox_inches_restore)
1250+
bbox_inches_restore=bbox_inches_restore)
12541251

12551252
self.figure.draw(renderer)
12561253

‎lib/matplotlib/backends/backend_svg.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,17 +1219,16 @@ def print_svgz(self, filename, *args, **kwargs):
12191219
gzip.GzipFile(mode='w',fileobj=fh)asgzipwriter:
12201220
returnself.print_svg(gzipwriter)
12211221

1222-
def_print_svg(self,filename,fh,**kwargs):
1223-
image_dpi=kwargs.pop("dpi",72)
1222+
def_print_svg(
1223+
self,filename,fh,*,dpi=72,bbox_inches_restore=None,**kwargs):
12241224
self.figure.set_dpi(72.0)
12251225
width,height=self.figure.get_size_inches()
12261226
w,h=width*72,height*72
12271227

1228-
_bbox_inches_restore=kwargs.pop("bbox_inches_restore",None)
12291228
renderer=MixedModeRenderer(
1230-
self.figure,width,height,image_dpi,
1231-
RendererSVG(w,h,fh,filename,image_dpi),
1232-
bbox_inches_restore=_bbox_inches_restore)
1229+
self.figure,width,height,dpi,
1230+
RendererSVG(w,h,fh,filename,dpi),
1231+
bbox_inches_restore=bbox_inches_restore)
12331232

12341233
self.figure.draw(renderer)
12351234
renderer.finalize()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp