Skip to content

Commit aee51c8

Browse files
committed
Deprecate positional passing of most Artist constructor parameters
This should have very little impact on the practical use, as it's anyway error-prone to pass more than a few arguments by position. But enforcing keyword-only makes future API changes simpler for us.
1 parent d73ba9e commit aee51c8

File tree

14 files changed

+57
-15
lines changed

14 files changed

+57
-15
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
``Legend`` constructor
2-
~~~~~~~~~~~~~~~~~~~~~~
1+
Positional arguments in Artist constructors
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33

4-
All arguments to `.legend.Legend` other than *parent*, *handles*, and *labels*
5-
will become keyword-only in a future version.
4+
Passing all but the very few first arguments positionally in the constructors
5+
of Artists is deprecated. Most arguments will become keyword-only in a future
6+
version.

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5490,8 +5490,9 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
54905490
if aspect is None:
54915491
aspect = rcParams['image.aspect']
54925492
self.set_aspect(aspect)
5493-
im = mimage.AxesImage(self, cmap, norm, interpolation,
5494-
origin, extent, filternorm=filternorm,
5493+
im = mimage.AxesImage(self, cmap=cmap, norm=norm,
5494+
interpolation=interpolation, origin=origin,
5495+
extent=extent, filternorm=filternorm,
54955496
filterrad=filterrad, resample=resample,
54965497
interpolation_stage=interpolation_stage,
54975498
**kwargs)
@@ -6275,7 +6276,7 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
62756276
extent = xl, xr, yb, yt = x[0], x[-1], y[0], y[-1]
62766277
if style == "image":
62776278
im = mimage.AxesImage(
6278-
self, cmap, norm,
6279+
self, cmap=cmap, norm=norm,
62796280
data=C, alpha=alpha, extent=extent,
62806281
interpolation='nearest', origin='lower',
62816282
**kwargs)

lib/matplotlib/axis.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ def __str__(self):
643643
return "{}({},{})".format(
644644
type(self).__name__, *self.axes.transAxes.transform((0, 0)))
645645

646+
@_api.make_keyword_only("3.6", name="pickradius")
646647
def __init__(self, axes, pickradius=15):
647648
"""
648649
Parameters

lib/matplotlib/collections.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class Collection(artist.Artist, cm.ScalarMappable):
7575
_edge_default = False
7676

7777
@_docstring.interpd
78+
@_api.make_keyword_only("3.6", name="edgecolors")
7879
def __init__(self,
7980
edgecolors=None,
8081
facecolors=None,
@@ -1151,6 +1152,8 @@ def legend_elements(self, prop="colors", num="auto",
11511152

11521153

11531154
class PolyCollection(_CollectionWithSizes):
1155+
1156+
@_api.make_keyword_only("3.6", name="closed")
11541157
def __init__(self, verts, sizes=None, closed=True, **kwargs):
11551158
"""
11561159
Parameters
@@ -1287,6 +1290,7 @@ class RegularPolyCollection(_CollectionWithSizes):
12871290
_path_generator = mpath.Path.unit_regular_polygon
12881291
_factor = np.pi ** (-1/2)
12891292

1293+
@_api.make_keyword_only("3.6", name="rotation")
12901294
def __init__(self,
12911295
numsides,
12921296
rotation=0,
@@ -1503,6 +1507,7 @@ class EventCollection(LineCollection):
15031507

15041508
_edge_default = True
15051509

1510+
@_api.make_keyword_only("3.6", name="lineoffset")
15061511
def __init__(self,
15071512
positions, # Cannot be None.
15081513
orientation='horizontal',
@@ -1698,6 +1703,7 @@ def __init__(self, sizes, **kwargs):
16981703
class EllipseCollection(Collection):
16991704
"""A collection of ellipses, drawn using splines."""
17001705

1706+
@_api.make_keyword_only("3.6", name="units")
17011707
def __init__(self, widths, heights, angles, units='points', **kwargs):
17021708
"""
17031709
Parameters
@@ -1787,6 +1793,7 @@ class PatchCollection(Collection):
17871793
draw faster than a large number of patches.
17881794
"""
17891795

1796+
@_api.make_keyword_only("3.6", name="match_original")
17901797
def __init__(self, patches, match_original=False, **kwargs):
17911798
"""
17921799
*patches*

lib/matplotlib/figure.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2726,7 +2726,9 @@ def figimage(self, X, xo=0, yo=0, alpha=None, norm=None, cmap=None,
27262726
figsize = [x / dpi for x in (X.shape[1], X.shape[0])]
27272727
self.set_size_inches(figsize, forward=True)
27282728

2729-
im = mimage.FigureImage(self, cmap, norm, xo, yo, origin, **kwargs)
2729+
im = mimage.FigureImage(self, cmap=cmap, norm=norm,
2730+
offsetx=xo, offsety=yo,
2731+
origin=origin, **kwargs)
27302732
im.stale_callback = _stale_figure_callback
27312733

27322734
im.set_array(X)

lib/matplotlib/image.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ class AxesImage(_ImageBase):
902902
**kwargs : `.Artist` properties
903903
"""
904904

905+
@_api.make_keyword_only("3.6", name="cmap")
905906
def __init__(self, ax,
906907
cmap=None,
907908
norm=None,
@@ -1185,6 +1186,8 @@ class PcolorImage(AxesImage):
11851186
This uses a variation of the original irregular image code,
11861187
and it is used by pcolorfast for the corresponding grid type.
11871188
"""
1189+
1190+
@_api.make_keyword_only("3.6", name="cmap")
11881191
def __init__(self, ax,
11891192
x=None,
11901193
y=None,
@@ -1336,6 +1339,7 @@ class FigureImage(_ImageBase):
13361339

13371340
_interpolation = 'nearest'
13381341

1342+
@_api.make_keyword_only("3.6", name="cmap")
13391343
def __init__(self, fig,
13401344
cmap=None,
13411345
norm=None,
@@ -1394,6 +1398,7 @@ def set_data(self, A):
13941398
class BboxImage(_ImageBase):
13951399
"""The Image class whose size is determined by the given bbox."""
13961400

1401+
@_api.make_keyword_only("3.6", name="cmap")
13971402
def __init__(self, bbox,
13981403
cmap=None,
13991404
norm=None,

lib/matplotlib/lines.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ def __str__(self):
264264
return "Line2D(%s)" % ",".join(
265265
map("({:g},{:g})".format, self._x, self._y))
266266

267+
@_api.make_keyword_only("3.6", name="linewidth")
267268
def __init__(self, xdata, ydata,
268269
linewidth=None, # all Nones default to rc
269270
linestyle=None,

lib/matplotlib/offsetbox.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ class PaddedBox(OffsetBox):
498498
The `.PaddedBox` contains a `.FancyBboxPatch` that is used to visualize
499499
it when rendering.
500500
"""
501+
502+
@_api.make_keyword_only("3.6", name="draw_frame")
501503
def __init__(self, child, pad=None, draw_frame=False, patch_attrs=None):
502504
"""
503505
Parameters
@@ -688,6 +690,7 @@ class TextArea(OffsetBox):
688690
child text.
689691
"""
690692

693+
@_api.make_keyword_only("3.6", name="textprops")
691694
def __init__(self, s,
692695
textprops=None,
693696
multilinebaseline=False,
@@ -919,6 +922,7 @@ class AnchoredOffsetbox(OffsetBox):
919922
'center': 10,
920923
}
921924

925+
@_api.make_keyword_only("3.6", name="pad")
922926
def __init__(self, loc,
923927
pad=0.4, borderpad=0.5,
924928
child=None, prop=None, frameon=True,
@@ -1118,6 +1122,7 @@ class AnchoredText(AnchoredOffsetbox):
11181122
AnchoredOffsetbox with Text.
11191123
"""
11201124

1125+
@_api.make_keyword_only("3.6", name="pad")
11211126
def __init__(self, s, loc, pad=0.4, borderpad=0.5, prop=None, **kwargs):
11221127
"""
11231128
Parameters
@@ -1157,6 +1162,8 @@ def __init__(self, s, loc, pad=0.4, borderpad=0.5, prop=None, **kwargs):
11571162

11581163

11591164
class OffsetImage(OffsetBox):
1165+
1166+
@_api.make_keyword_only("3.6", name="zoom")
11601167
def __init__(self, arr,
11611168
zoom=1,
11621169
cmap=None,
@@ -1252,6 +1259,7 @@ def __str__(self):
12521259
return "AnnotationBbox(%g,%g)" % (self.xy[0], self.xy[1])
12531260

12541261
@_docstring.dedent_interpd
1262+
@_api.make_keyword_only("3.6", name="xycoords")
12551263
def __init__(self, offsetbox, xy,
12561264
xybox=None,
12571265
xycoords='data',

lib/matplotlib/patches.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Patch(artist.Artist):
4444
# subclass-by-subclass basis.
4545
_edge_default = False
4646

47+
@_api.make_keyword_only("3.6", name="edgecolor")
4748
def __init__(self,
4849
edgecolor=None,
4950
facecolor=None,
@@ -690,6 +691,7 @@ def __str__(self):
690691
return fmt % pars
691692

692693
@_docstring.dedent_interpd
694+
@_api.make_keyword_only("3.6", name="angle")
693695
def __init__(self, xy, width, height, angle=0.0, *,
694696
rotation_point='xy', **kwargs):
695697
"""
@@ -892,6 +894,7 @@ def __str__(self):
892894
self.orientation)
893895

894896
@_docstring.dedent_interpd
897+
@_api.make_keyword_only("3.6", name="radius")
895898
def __init__(self, xy, numVertices, radius=5, orientation=0,
896899
**kwargs):
897900
"""
@@ -1079,6 +1082,7 @@ def __str__(self):
10791082
return "Polygon0()"
10801083

10811084
@_docstring.dedent_interpd
1085+
@_api.make_keyword_only("3.6", name="closed")
10821086
def __init__(self, xy, closed=True, **kwargs):
10831087
"""
10841088
*xy* is a numpy array with shape Nx2.
@@ -1175,6 +1179,7 @@ def __str__(self):
11751179
return fmt % pars
11761180

11771181
@_docstring.dedent_interpd
1182+
@_api.make_keyword_only("3.6", name="width")
11781183
def __init__(self, center, r, theta1, theta2, width=None, **kwargs):
11791184
"""
11801185
A wedge centered at *x*, *y* center with radius *r* that
@@ -1271,6 +1276,7 @@ def __str__(self):
12711276
closed=True)
12721277

12731278
@_docstring.dedent_interpd
1279+
@_api.make_keyword_only("3.6", name="width")
12741280
def __init__(self, x, y, dx, dy, width=1.0, **kwargs):
12751281
"""
12761282
Draws an arrow from (*x*, *y*) to (*x* + *dx*, *y* + *dy*).
@@ -1326,6 +1332,7 @@ def __str__(self):
13261332
return "FancyArrow()"
13271333

13281334
@_docstring.dedent_interpd
1335+
@_api.make_keyword_only("3.6", name="width")
13291336
def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False,
13301337
head_width=None, head_length=None, shape='full', overhang=0,
13311338
head_starts_at_zero=False, **kwargs):
@@ -1496,6 +1503,7 @@ def __str__(self):
14961503
return s % (self.xy[0], self.xy[1], self.radius, self.numvertices)
14971504

14981505
@_docstring.dedent_interpd
1506+
@_api.make_keyword_only("3.6", name="resolution")
14991507
def __init__(self, xy, radius=5,
15001508
resolution=20, # the number of vertices
15011509
** kwargs):
@@ -1509,7 +1517,8 @@ def __init__(self, xy, radius=5,
15091517
15101518
%(Patch:kwdoc)s
15111519
"""
1512-
super().__init__(xy, resolution, radius, orientation=0, **kwargs)
1520+
super().__init__(
1521+
xy, resolution, radius=radius, orientation=0, **kwargs)
15131522

15141523

15151524
class Ellipse(Patch):
@@ -1522,6 +1531,7 @@ def __str__(self):
15221531
return fmt % pars
15231532

15241533
@_docstring.dedent_interpd
1534+
@_api.make_keyword_only("3.6", name="angle")
15251535
def __init__(self, xy, width, height, angle=0, **kwargs):
15261536
"""
15271537
Parameters
@@ -1913,6 +1923,7 @@ def __str__(self):
19131923
return fmt % pars
19141924

19151925
@_docstring.dedent_interpd
1926+
@_api.make_keyword_only("3.6", name="angle")
19161927
def __init__(self, xy, width, height, angle=0.0,
19171928
theta1=0.0, theta2=360.0, **kwargs):
19181929
"""
@@ -1953,7 +1964,7 @@ def __init__(self, xy, width, height, angle=0.0,
19531964
if fill:
19541965
raise ValueError("Arc objects can not be filled")
19551966

1956-
super().__init__(xy, width, height, angle, **kwargs)
1967+
super().__init__(xy, width, height, angle=angle, **kwargs)
19571968

19581969
self.theta1 = theta1
19591970
self.theta2 = theta2
@@ -3916,6 +3927,7 @@ def __str__(self):
39163927
return s % (self._x, self._y, self._width, self._height)
39173928

39183929
@_docstring.dedent_interpd
3930+
@_api.make_keyword_only("3.6", name="mutation_scale")
39193931
@_api.delete_parameter("3.4", "bbox_transmuter", alternative="boxstyle")
39203932
def __init__(self, xy, width, height,
39213933
boxstyle="round", bbox_transmuter=None,
@@ -4207,6 +4219,7 @@ def __str__(self):
42074219
return f"{type(self).__name__}({self._path_original})"
42084220

42094221
@_docstring.dedent_interpd
4222+
@_api.make_keyword_only("3.6", name="path")
42104223
def __init__(self, posA=None, posB=None, path=None,
42114224
arrowstyle="simple", connectionstyle="arc3",
42124225
patchA=None, patchB=None,
@@ -4522,6 +4535,7 @@ def __str__(self):
45224535
(self.xy1[0], self.xy1[1], self.xy2[0], self.xy2[1])
45234536

45244537
@_docstring.dedent_interpd
4538+
@_api.make_keyword_only("3.6", name="axesA")
45254539
def __init__(self, xyA, xyB, coordsA, coordsB=None,
45264540
axesA=None, axesB=None,
45274541
arrowstyle="-",

lib/matplotlib/table.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Cell(Rectangle):
5151
'vertical': 'RL'
5252
}
5353

54+
@_api.make_keyword_only("3.6", name="edgecolor")
5455
def __init__(self, xy, width, height,
5556
edgecolor='k', facecolor='w',
5657
fill=True,

0 commit comments

Comments
 (0)