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

Commitf4078d3

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 parent9b48fd8 commitf4078d3

37 files changed

+197
-322
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
@@ -1772,7 +1772,7 @@ def param(func):
17721772
pass
17731773

17741774
@functools.wraps(func)
1775-
definner(ax,*args,**kwargs):
1775+
definner(ax,*args,data=None,**kwargs):
17761776
# this is needed because we want to change these values if
17771777
# arg_names_at_runtime==True, but python does not allow assigning
17781778
# to a variable in a outer scope. So use some new local ones and
@@ -1783,8 +1783,6 @@ def inner(ax, *args, **kwargs):
17831783

17841784
label=None
17851785

1786-
data=kwargs.pop('data',None)
1787-
17881786
ifdataisNone:# data validation
17891787
args=tuple(sanitize_sequence(a)forainargs)
17901788
else:

‎lib/matplotlib/axes/_axes.py

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

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

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

‎lib/matplotlib/axes/_base.py

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

2714-
defticklabel_format(self,**kwargs):
2714+
defticklabel_format(self,*,axis='both',style='',scilimits=None,
2715+
useOffset=None,useLocale=None,useMathText=None):
27152716
"""
27162717
Change the `~matplotlib.ticker.ScalarFormatter` used by
27172718
default for linear axes.
@@ -2721,6 +2722,7 @@ def ticklabel_format(self, **kwargs):
27212722
============== =========================================
27222723
Keyword Description
27232724
============== =========================================
2725+
*axis* [ 'x' | 'y' | 'both' ]
27242726
*style* [ 'sci' (or 'scientific') | 'plain' ]
27252727
plain turns off scientific notation
27262728
*scilimits* (m, n), pair of integers; if *style*
@@ -2733,7 +2735,6 @@ def ticklabel_format(self, **kwargs):
27332735
if False, no offset will be used; if a
27342736
numeric offset is specified, it will be
27352737
used.
2736-
*axis* [ 'x' | 'y' | 'both' ]
27372738
*useLocale* If True, format the number according to
27382739
the current locale. This affects things
27392740
such as the character used for the
@@ -2752,12 +2753,8 @@ def ticklabel_format(self, **kwargs):
27522753
:exc:`AttributeError` will be raised.
27532754
27542755
"""
2755-
style=kwargs.pop('style','').lower()
2756-
scilimits=kwargs.pop('scilimits',None)
2757-
useOffset=kwargs.pop('useOffset',None)
2758-
useLocale=kwargs.pop('useLocale',None)
2759-
useMathText=kwargs.pop('useMathText',None)
2760-
axis=kwargs.pop('axis','both').lower()
2756+
style=style.lower()
2757+
axis=axis.lower()
27612758
ifscilimitsisnotNone:
27622759
try:
27632760
m,n=scilimits

‎lib/matplotlib/axis.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ def set_pickradius(self, pickradius):
16121612
"""
16131613
self.pickradius=pickradius
16141614

1615-
defset_ticklabels(self,ticklabels,*args,**kwargs):
1615+
defset_ticklabels(self,ticklabels,*args,minor=False,**kwargs):
16161616
"""
16171617
Set the text values of the tick labels. Return a list of Text
16181618
instances. Use *kwarg* *minor=True* to select minor ticks.
@@ -1641,7 +1641,6 @@ def set_ticklabels(self, ticklabels, *args, **kwargs):
16411641
# replace the ticklabels list with the processed one
16421642
ticklabels=get_labels
16431643

1644-
minor=kwargs.pop('minor',False)
16451644
ifminor:
16461645
self.set_minor_formatter(mticker.FixedFormatter(ticklabels))
16471646
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
@@ -541,7 +541,7 @@ def print_to_buffer(self):
541541

542542
if_has_pil:
543543
# add JPEG support
544-
defprint_jpg(self,filename_or_obj,*args,**kwargs):
544+
defprint_jpg(self,filename_or_obj,*args,dryrun=False,**kwargs):
545545
"""
546546
Other Parameters
547547
----------------
@@ -562,7 +562,7 @@ def print_jpg(self, filename_or_obj, *args, **kwargs):
562562
should be stored as a progressive JPEG file.
563563
"""
564564
buf,size=self.print_to_buffer()
565-
ifkwargs.pop("dryrun",False):
565+
ifdryrun:
566566
return
567567
# The image is "pasted" onto a white background image to safely
568568
# handle any transparency
@@ -583,9 +583,9 @@ def print_jpg(self, filename_or_obj, *args, **kwargs):
583583
print_jpeg=print_jpg
584584

585585
# add TIFF support
586-
defprint_tif(self,filename_or_obj,*args,**kwargs):
586+
defprint_tif(self,filename_or_obj,*args,dryrun=False,**kwargs):
587587
buf,size=self.print_to_buffer()
588-
ifkwargs.pop("dryrun",False):
588+
ifdryrun:
589589
return
590590
image=Image.frombuffer('RGBA',size,buf,'raw','RGBA',0,1)
591591
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
@@ -790,8 +790,9 @@ class FigureCanvasPgf(FigureCanvasBase):
790790
defget_default_filetype(self):
791791
return'pdf'
792792

793-
def_print_pgf_to_fh(self,fh,*args,**kwargs):
794-
ifkwargs.get("dryrun",False):
793+
def_print_pgf_to_fh(self,fh,*args,
794+
dryrun=False,bbox_inches_restore=None,**kwargs):
795+
ifdryrun:
795796
renderer=RendererPgf(self.figure,None,dummy=True)
796797
self.figure.draw(renderer)
797798
return
@@ -837,10 +838,9 @@ def _print_pgf_to_fh(self, fh, *args, **kwargs):
837838
r"\pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{%fin}{%fin}}"
838839
% (w,h))
839840
writeln(fh,r"\pgfusepath{use as bounding box, clip}")
840-
_bbox_inches_restore=kwargs.pop("bbox_inches_restore",None)
841841
renderer=MixedModeRenderer(self.figure,w,h,dpi,
842842
RendererPgf(self.figure,fh),
843-
bbox_inches_restore=_bbox_inches_restore)
843+
bbox_inches_restore=bbox_inches_restore)
844844
self.figure.draw(renderer)
845845

846846
# end the pgfpicture environment

‎lib/matplotlib/backends/backend_ps.py

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

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

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

1044-
10451044
# mixed mode rendering
1046-
_bbox_inches_restore=kwargs.pop("bbox_inches_restore",None)
10471045
ps_renderer=self._renderer_class(width,height,self._pswriter,
10481046
imagedpi=dpi)
10491047
renderer=MixedModeRenderer(self.figure,
10501048
width,height,dpi,ps_renderer,
1051-
bbox_inches_restore=_bbox_inches_restore)
1049+
bbox_inches_restore=bbox_inches_restore)
10521050

10531051
self.figure.draw(renderer)
10541052

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

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

1238-
dryrun=kwargs.get("dryrun",False)
12391237
ifdryrun:
12401238
classNullWriter(object):
12411239
defwrite(self,*kl,**kwargs):
@@ -1246,12 +1244,11 @@ def write(self, *kl, **kwargs):
12461244
self._pswriter=io.StringIO()
12471245

12481246
# mixed mode rendering
1249-
_bbox_inches_restore=kwargs.pop("bbox_inches_restore",None)
12501247
ps_renderer=self._renderer_class(width,height,
12511248
self._pswriter,imagedpi=dpi)
12521249
renderer=MixedModeRenderer(self.figure,
12531250
width,height,dpi,ps_renderer,
1254-
bbox_inches_restore=_bbox_inches_restore)
1251+
bbox_inches_restore=bbox_inches_restore)
12551252

12561253
self.figure.draw(renderer)
12571254

‎lib/matplotlib/backends/backend_svg.py

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

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

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

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp