Skip to content

Commit 0c6af5b

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 0c6af5b

File tree

9 files changed

+43
-4
lines changed

9 files changed

+43
-4
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/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/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: 13 additions & 0 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", closed=True)
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):
@@ -1522,6 +1530,7 @@ def __str__(self):
15221530
return fmt % pars
15231531

15241532
@_docstring.dedent_interpd
1533+
@_api.make_keyword_only("3.6", name="angle")
15251534
def __init__(self, xy, width, height, angle=0, **kwargs):
15261535
"""
15271536
Parameters
@@ -1913,6 +1922,7 @@ def __str__(self):
19131922
return fmt % pars
19141923

19151924
@_docstring.dedent_interpd
1925+
@_api.make_keyword_only("3.6", name="angle")
19161926
def __init__(self, xy, width, height, angle=0.0,
19171927
theta1=0.0, theta2=360.0, **kwargs):
19181928
"""
@@ -3916,6 +3926,7 @@ def __str__(self):
39163926
return s % (self._x, self._y, self._width, self._height)
39173927

39183928
@_docstring.dedent_interpd
3929+
@_api.make_keyword_only("3.6", name="bbox_transmuter")
39193930
@_api.delete_parameter("3.4", "bbox_transmuter", alternative="boxstyle")
39203931
def __init__(self, xy, width, height,
39213932
boxstyle="round", bbox_transmuter=None,
@@ -4207,6 +4218,7 @@ def __str__(self):
42074218
return f"{type(self).__name__}({self._path_original})"
42084219

42094220
@_docstring.dedent_interpd
4221+
@_api.make_keyword_only("3.6", name="path")
42104222
def __init__(self, posA=None, posB=None, path=None,
42114223
arrowstyle="simple", connectionstyle="arc3",
42124224
patchA=None, patchB=None,
@@ -4522,6 +4534,7 @@ def __str__(self):
45224534
(self.xy1[0], self.xy1[1], self.xy2[0], self.xy2[1])
45234535

45244536
@_docstring.dedent_interpd
4537+
@_api.make_keyword_only("3.6", name="axesA")
45254538
def __init__(self, xyA, xyB, coordsA, coordsB=None,
45264539
axesA=None, axesB=None,
45274540
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,

lib/matplotlib/text.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class Text(Artist):
128128
def __repr__(self):
129129
return "Text(%s, %s, %s)" % (self._x, self._y, repr(self._text))
130130

131+
@_api.make_keyword_only("3.6", name="color")
131132
def __init__(self,
132133
x=0, y=0, text='',
133134
color=None, # defaults to rc params
@@ -1628,6 +1629,7 @@ class Annotation(Text, _AnnotationBase):
16281629
def __str__(self):
16291630
return "Annotation(%g, %g, %r)" % (self.xy[0], self.xy[1], self._text)
16301631

1632+
@_api.make_keyword_only("3.6", name="xycoords")
16311633
def __init__(self, text, xy,
16321634
xytext=None,
16331635
xycoords='data',

0 commit comments

Comments
 (0)