8000 Merge pull request #23177 from timhoffm/constructors-kw-only · matplotlib/matplotlib@dab648a · GitHub
[go: up one dir, main page]

Skip to content

Commit dab648a

Browse files
authored
Merge pull request #23177 from timhoffm/constructors-kw-only
Deprecate positional passing of most Artist constructor parameters
2 parents 9bca34e + aee51c8 commit dab648a

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
@@ -5491,8 +5491,9 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
54915491
if aspect is None:
54925492
aspect = rcParams['image.aspect']
54935493
self.set_aspect(aspect)
5494-
im = mimage.AxesImage(self, cmap, norm, interpolation,
5495-
origin, extent, filternorm=filternorm,
5494+
im = mimage.AxesImage(self, cmap=cmap, norm=norm,
5495+
interpolation=interpolation, origin=origin,
5496+
extent=extent, filternorm=filternorm,
54965497
filterrad=filterrad, resample=resample,
54975498
interpolation_stage=interpolation_stage,
54985499
**kwargs)
@@ -6276,7 +6277,7 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
62766277
extent = xl, xr, yb, yt = x[0], x[-1], y[0], y[-1]
62776278
if style == "image":
62786279
im = mimage.AxesImage(
6279-
self, cmap, norm,
6280+
self, cmap=cmap, norm=norm,
62806281
data=C, alpha=alpha, extent=extent,
62816282
interpolation='nearest', origin='lower',
62826283
**kwargs)

lib/matplotlib/axis.py

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

647+
@_api.make_keyword_only("3.6", name="pickradius")
647648
def __init__(self, axes, pickradius=15):
648649
"""
649650
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
@@ -1785,6 +1791,7 @@ class PatchCollection(Collection):
17851791
collection of patches.
17861792
"""
17871793

1794+
@_api.make_keyword_only("3.6", name="match_original")
17881795
def __init__(self, patches, match_original=False, **kwargs):
17891796
"""
17901797
Parameters

lib/matplotlib/figure.py

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

2735-
im = mimage.FigureImage(self, cmap, norm, xo, yo, origin, **kwargs)
2735+
im = mimage.FigureImage(self, cmap=cmap, norm=norm,
2736+
offsetx=xo, offsety=yo,
2737+
origin=origin, **kwargs)
27362738
im.stale_callback = _stale_figure_callback
27372739

27382740
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
@@ -268,6 +268,7 @@ def __str__(self):
268268
return "Line2D(%s)" % ",".join(
269269
map("({:g},{:g})".format, self._x, self._y))
270270

271+
@_api.make_keyword_only("3.6", name="linewidth")
271272
def __init__(self, xdata, ydata,
272273
linewidth=None, # all Nones default to rc
273274
linestyle=None,

lib/matplotlib/offsetbox.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@ class PaddedBox(OffsetBox):
500500
The `.PaddedBox` contains a `.FancyBboxPatch` that is used to visualize
501501
it when rendering.
502502
"""
503+
504+
@_api.make_keyword_only("3.6", name="draw_frame")
503505
def __init__(self, child, pad=None, draw_frame=False, patch_attrs=None):
504506
"""
505507
Parameters
@@ -692,6 +694,7 @@ class TextArea(OffsetBox):
692694
child text.
693695
"""
694696

697+
@_api.make_keyword_only("3.6", name="textprops")
695698
def __init__(self, s,
696699
textprops=None,
697700
multilinebaseline=False,
@@ -927,6 +930,7 @@ class AnchoredOffsetbox(OffsetBox):
927930
'center': 10,
928931
}
929932

933+
@_api.make_keyword_only("3.6", name="pad")
930934
def __init__(self, loc,
931935
pad=0.4, borderpad=0.5,
932936
child=None, prop=None, frameon=True,
@@ -1129,6 +1133,7 @@ class AnchoredText(AnchoredOffsetbox):
11291133
AnchoredOffsetbox with Text.
11301134
"""
11311135

1136+
@_api.make_keyword_only("3.6", name="pad")
11321137
def __init__(self, s, loc, pad=0.4, borderpad=0.5, prop=None, **kwargs):
11331138
"""
11341139
Parameters
@@ -1168,6 +1173,8 @@ def __init__(self, s, loc, pad=0.4, borderpad=0.5, prop=None, **kwargs):
11681173

11691174

11701175
class OffsetImage(OffsetBox):
1176+
1177+
@_api.make_keyword_only("3.6", name="zoom")
11711178
def __init__(self, arr,
11721179
zoom=1,
11731180
cmap=None,
@@ -1265,6 +1272,7 @@ def __str__(self):
12651272
return "AnnotationBbox(%g,%g)" % (self.xy[0], self.xy[1])
12661273

12671274
@_docstring.dedent_interpd
1275+
@_api.make_keyword_only("3.6", name="xycoords")
12681276
def __init__(self, offsetbox, xy,
12691277
xybox=None,
12701278
xycoords='data',

lib/matplotlib/patches.py

Copy file name to clipboard
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
@@ -3840,6 +3851,7 @@ def __str__(self):
38403851
return s % (self._x, self._y, self._width, self._height)
38413852

38423853
@_docstring.dedent_interpd
3854+
@_api.make_keyword_only("3.6", name="mutation_scale")
38433855
@_api.delete_parameter("3.4", "bbox_transmuter", alternative="boxstyle")
38443856
def __init__(self, xy, width, height,
38453857
boxstyle="round", bbox_transmuter=None,
@@ -4129,6 +4141,7 @@ def __str__(self):
41294141
return f"{type(self).__name__}({self._path_original})"
41304142

41314143
@_docstring.dedent_interpd
4144+
@_api.make_keyword_only("3.6", name="path")
41324145
def __init__(self, posA=None, posB=None, path=None,
41334146
arrowstyle="simple", connectionstyle="arc3",
41344147
patchA=None, patchB=None,
@@ -4444,6 +4457,7 @@ def __str__(self):
44444457
(self.xy1[0], self.xy1[1], self.xy2[0], self.xy2[1])
44454458

44464459
@_docstring.dedent_interpd
4460+
@_api.make_keyword_only("3.6", name="axesA")
44474461
def __init__(self, xyA, xyB, coordsA, coordsB=None,
44484462
axesA=None, axesB=None,
44494463
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/tests/test_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7626,7 +7626,7 @@ def test_nan_barlabels():
76267626

76277627
def test_patch_bounds(): # PR 19078
76287628
fig, ax = plt.subplots()
7629-
ax.add_patch(mpatches.Wedge((0, -1), 1.05, 60, 120, 0.1))
7629+
ax.add_patch(mpatches.Wedge((0, -1), 1.05, 60, 120, width=0.1))
76307630
bot = 1.9*np.sin(15*np.pi/180)**2
76317631
np.testing.assert_array_almost_equal_nulp(
76327632
np.array((-0.525, -(bot+0.05), 1.05, bot+0.1)), ax.dataLim.bounds, 16)

lib/matplotlib/tests/test_collections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,9 +1156,9 @@ def test_set_offsets_late():
11561156

11571157
def test_set_offset_transform():
11581158
skew = mtransforms.Affine2D().skew(2, 2)
1159-
init = mcollections.Collection([], offset_transform=skew)
1159+
init = mcollections.Collection(offset_transform=skew)
11601160

1161-
late = mcollections.Collection([])
1161+
late = mcollections.Collection()
11621162
late.set_offset_transform(skew)
11631163

11641164
assert skew == init.get_offset_transform() == late.get_offset_transform()

lib/matplotlib/tests/test_patches.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ def test_datetime_datetime_fails():
547547

548548

549549
def test_contains_point():
550-
ell = mpatches.Ellipse((0.5, 0.5), 0.5, 1.0, 0)
550+
ell = mpatches.Ellipse((0.5, 0.5), 0.5, 1.0)
551551
points = [(0.0, 0.5), (0.2, 0.5), (0.25, 0.5), (0.5, 0.5)]
552552
path = ell.get_path()
553553
transform = ell.get_transform()
@@ -560,7 +560,7 @@ def test_contains_point():
560560

561561

562562
def test_contains_points():
563-
ell = mpatches.Ellipse((0.5, 0.5), 0.5, 1.0, 0)
563+
ell = mpatches.Ellipse((0.5, 0.5), 0.5, 1.0)
564564
points = [(0.0, 0.5), (0.2, 0.5), (0.25, 0.5), (0.5, 0.5)]
565565
path = ell.get_path()
566566
transform = ell.get_transform()

lib/matplotlib/text.py

Lines changed: 1 addition & 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

0 commit comments

Comments
 (0)
0