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

Commit2e37748

Browse files
committed
Remove deprecations and make arguments keyword only
1 parent2cbdff8 commit2e37748

File tree

6 files changed

+41
-165
lines changed

6 files changed

+41
-165
lines changed

‎ci/mypy-stubtest-allowlist.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ matplotlib.cm.register_cmap
5454
matplotlib.cm.unregister_cmap
5555
matplotlib.collections.PolyCollection.span_where
5656
matplotlib.gridspec.GridSpecBase.get_grid_positions
57-
matplotlib.widgets.MultiCursor.needclear
5857

5958
# 3.8 deprecations
6059
matplotlib.cbook.get_sample_data
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Most arguments to widgets have been made keyword-only
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Passing all but the very few first arguments positionally in the constructors
5+
of Widgets is now keyword-only. In general, all optional arguments are keyword-only.
6+
7+
``RadioButtons.circles``
8+
~~~~~~~~~~~~~~~~~~~~~~~~
9+
10+
... is removed. (``RadioButtons`` now draws itself using `~.Axes.scatter`.)
11+
12+
``CheckButtons.rectangles`` and ``CheckButtons.lines``
13+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14+
15+
``CheckButtons.rectangles`` and ``CheckButtons.lines`` are removed.
16+
(``CheckButtons`` now draws itself using `~.Axes.scatter`.)
17+
18+
Remove unused parameter *x* to ``TextBox.begin_typing``
19+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20+
21+
This parameter was unused in the method, but was a required argument.
22+
23+
``MultiCursor.needclear``
24+
~~~~~~~~~~~~~~~~~~~~~~~~~
25+
26+
... is removed.

‎lib/matplotlib/tests/test_widgets.py

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
importmatplotlib.colorsasmcolors
88
importmatplotlib.widgetsaswidgets
99
importmatplotlib.pyplotasplt
10-
frommatplotlib.patchesimportRectangle
11-
frommatplotlib.linesimportLine2D
1210
frommatplotlib.testing.decoratorsimportcheck_figures_equal,image_comparison
1311
frommatplotlib.testing.widgetsimport (click_and_drag,do_event,get_ax,
1412
mock_event,noop)
@@ -1055,16 +1053,10 @@ def test_check_radio_buttons_image():
10551053

10561054
rax1=fig.add_axes((0.05,0.7,0.2,0.15))
10571055
rb1=widgets.RadioButtons(rax1, ('Radio 1','Radio 2','Radio 3'))
1058-
withpytest.warns(DeprecationWarning,
1059-
match='The circles attribute was deprecated'):
1060-
rb1.circles# Trigger the old-style elliptic radiobuttons.
10611056

10621057
rax2=fig.add_axes((0.05,0.5,0.2,0.15))
10631058
cb1=widgets.CheckButtons(rax2, ('Check 1','Check 2','Check 3'),
10641059
(False,True,True))
1065-
withpytest.warns(DeprecationWarning,
1066-
match='The rectangles attribute was deprecated'):
1067-
cb1.rectangles# Trigger old-style Rectangle check boxes
10681060

10691061
rax3=fig.add_axes((0.05,0.3,0.2,0.15))
10701062
rb3=widgets.RadioButtons(
@@ -1164,57 +1156,6 @@ def test_check_button_props(fig_test, fig_ref):
11641156
cb.set_check_props({**check_props,'s': (24/2)**2})
11651157

11661158

1167-
@check_figures_equal(extensions=["png"])
1168-
deftest_check_buttons_rectangles(fig_test,fig_ref):
1169-
# Test should be removed once .rectangles is removed
1170-
cb=widgets.CheckButtons(fig_test.subplots(), ["",""],
1171-
[False,False])
1172-
withpytest.warns(DeprecationWarning,
1173-
match='The rectangles attribute was deprecated'):
1174-
cb.rectangles
1175-
ax=fig_ref.add_subplot(xticks=[],yticks=[])
1176-
ys= [2/3,1/3]
1177-
dy=1/3
1178-
w,h=dy/2,dy/2
1179-
rectangles= [
1180-
Rectangle(xy=(0.05,ys[i]-h/2),width=w,height=h,
1181-
edgecolor="black",
1182-
facecolor="none",
1183-
transform=ax.transAxes
1184-
)
1185-
fori,yinenumerate(ys)
1186-
]
1187-
forrectangleinrectangles:
1188-
ax.add_patch(rectangle)
1189-
1190-
1191-
@check_figures_equal(extensions=["png"])
1192-
deftest_check_buttons_lines(fig_test,fig_ref):
1193-
# Test should be removed once .lines is removed
1194-
cb=widgets.CheckButtons(fig_test.subplots(), ["",""], [True,True])
1195-
withpytest.warns(DeprecationWarning,
1196-
match='The lines attribute was deprecated'):
1197-
cb.lines
1198-
forrectangleincb._rectangles:
1199-
rectangle.set_visible(False)
1200-
ax=fig_ref.add_subplot(xticks=[],yticks=[])
1201-
ys= [2/3,1/3]
1202-
dy=1/3
1203-
w,h=dy/2,dy/2
1204-
lineparams= {'color':'k','linewidth':1.25,
1205-
'transform':ax.transAxes,
1206-
'solid_capstyle':'butt'}
1207-
fori,yinenumerate(ys):
1208-
x,y=0.05,y-h/2
1209-
l1=Line2D([x,x+w], [y+h,y],**lineparams)
1210-
l2=Line2D([x,x+w], [y,y+h],**lineparams)
1211-
1212-
l1.set_visible(True)
1213-
l2.set_visible(True)
1214-
ax.add_line(l1)
1215-
ax.add_line(l2)
1216-
1217-
12181159
deftest_slider_slidermin_slidermax_invalid():
12191160
fig,ax=plt.subplots()
12201161
# test min/max with floats

‎lib/matplotlib/widgets.py

Lines changed: 14 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .import (_api,_docstring,backend_tools,cbook,collections,colors,
2222
textasmtext,ticker,transforms)
2323
from .linesimportLine2D
24-
from .patchesimportCircle,Rectangle,Ellipse,Polygon
24+
from .patchesimportRectangle,Ellipse,Polygon
2525
from .transformsimportTransformedPatchPath,Affine2D
2626

2727

@@ -355,11 +355,10 @@ class Slider(SliderBase):
355355
Slider value.
356356
"""
357357

358-
@_api.make_keyword_only("3.7",name="valinit")
359-
def__init__(self,ax,label,valmin,valmax,valinit=0.5,valfmt=None,
358+
def__init__(self,ax,label,valmin,valmax,*,valinit=0.5,valfmt=None,
360359
closedmin=True,closedmax=True,slidermin=None,
361360
slidermax=None,dragging=True,valstep=None,
362-
orientation='horizontal',*,initcolor='r',
361+
orientation='horizontal',initcolor='r',
363362
track_color='lightgrey',handle_style=None,**kwargs):
364363
"""
365364
Parameters
@@ -627,13 +626,13 @@ class RangeSlider(SliderBase):
627626
Slider value.
628627
"""
629628

630-
@_api.make_keyword_only("3.7",name="valinit")
631629
def__init__(
632630
self,
633631
ax,
634632
label,
635633
valmin,
636634
valmax,
635+
*,
637636
valinit=None,
638637
valfmt=None,
639638
closedmin=True,
@@ -1283,60 +1282,6 @@ def disconnect(self, cid):
12831282
"""Remove the observer with connection id *cid*."""
12841283
self._observers.disconnect(cid)
12851284

1286-
@_api.deprecated("3.7",
1287-
addendum="Any custom property styling may be lost.")
1288-
@property
1289-
defrectangles(self):
1290-
ifnothasattr(self,"_rectangles"):
1291-
ys=np.linspace(1,0,len(self.labels)+2)[1:-1]
1292-
dy=1./ (len(self.labels)+1)
1293-
w,h=dy/2,dy/2
1294-
rectangles=self._rectangles= [
1295-
Rectangle(xy=(0.05,ys[i]-h/2),width=w,height=h,
1296-
edgecolor="black",
1297-
facecolor="none",
1298-
transform=self.ax.transAxes
1299-
)
1300-
fori,yinenumerate(ys)
1301-
]
1302-
self._frames.set_visible(False)
1303-
forrectangleinrectangles:
1304-
self.ax.add_patch(rectangle)
1305-
ifnothasattr(self,"_lines"):
1306-
with_api.suppress_matplotlib_deprecation_warning():
1307-
_=self.lines
1308-
returnself._rectangles
1309-
1310-
@_api.deprecated("3.7",
1311-
addendum="Any custom property styling may be lost.")
1312-
@property
1313-
deflines(self):
1314-
ifnothasattr(self,"_lines"):
1315-
ys=np.linspace(1,0,len(self.labels)+2)[1:-1]
1316-
self._checks.set_visible(False)
1317-
dy=1./ (len(self.labels)+1)
1318-
w,h=dy/2,dy/2
1319-
self._lines= []
1320-
current_status=self.get_status()
1321-
lineparams= {'color':'k','linewidth':1.25,
1322-
'transform':self.ax.transAxes,
1323-
'solid_capstyle':'butt',
1324-
'animated':self._useblit}
1325-
fori,yinenumerate(ys):
1326-
x,y=0.05,y-h/2
1327-
l1=Line2D([x,x+w], [y+h,y],**lineparams)
1328-
l2=Line2D([x,x+w], [y,y+h],**lineparams)
1329-
1330-
l1.set_visible(current_status[i])
1331-
l2.set_visible(current_status[i])
1332-
self._lines.append((l1,l2))
1333-
self.ax.add_line(l1)
1334-
self.ax.add_line(l2)
1335-
ifnothasattr(self,"_rectangles"):
1336-
with_api.suppress_matplotlib_deprecation_warning():
1337-
_=self.rectangles
1338-
returnself._lines
1339-
13401285

13411286
classTextBox(AxesWidget):
13421287
"""
@@ -1361,8 +1306,7 @@ class TextBox(AxesWidget):
13611306
The color of the text box when hovering.
13621307
"""
13631308

1364-
@_api.make_keyword_only("3.7",name="color")
1365-
def__init__(self,ax,label,initial='',
1309+
def__init__(self,ax,label,initial='',*,
13661310
color='.95',hovercolor='1',label_pad=.01,
13671311
textalignment="left"):
13681312
"""
@@ -1513,8 +1457,7 @@ def set_val(self, val):
15131457
self._observers.process('change',self.text)
15141458
self._observers.process('submit',self.text)
15151459

1516-
@_api.delete_parameter("3.7","x")
1517-
defbegin_typing(self,x=None):
1460+
defbegin_typing(self):
15181461
self.capturekeystrokes=True
15191462
# Disable keypress shortcuts, which may otherwise cause the figure to
15201463
# be saved, closed, etc., until the user stops typing. The way to
@@ -1856,23 +1799,6 @@ def disconnect(self, cid):
18561799
"""Remove the observer with connection id *cid*."""
18571800
self._observers.disconnect(cid)
18581801

1859-
@_api.deprecated("3.7",
1860-
addendum="Any custom property styling may be lost.")
1861-
@property
1862-
defcircles(self):
1863-
ifnothasattr(self,"_circles"):
1864-
radius=min(.5/ (len(self.labels)+1)-.01,.05)
1865-
circles=self._circles= [
1866-
Circle(xy=self._buttons.get_offsets()[i],edgecolor="black",
1867-
facecolor=self._buttons.get_facecolor()[i],
1868-
radius=radius,transform=self.ax.transAxes,
1869-
animated=self._useblit)
1870-
foriinrange(len(self.labels))]
1871-
self._buttons.set_visible(False)
1872-
forcircleincircles:
1873-
self.ax.add_patch(circle)
1874-
returnself._circles
1875-
18761802

18771803
classSubplotTool(Widget):
18781804
"""
@@ -1974,8 +1900,7 @@ class Cursor(AxesWidget):
19741900
--------
19751901
See :doc:`/gallery/widgets/cursor`.
19761902
"""
1977-
@_api.make_keyword_only("3.7","horizOn")
1978-
def__init__(self,ax,horizOn=True,vertOn=True,useblit=False,
1903+
def__init__(self,ax,*,horizOn=True,vertOn=True,useblit=False,
19791904
**lineprops):
19801905
super().__init__(ax)
19811906

@@ -2109,8 +2034,6 @@ def __init__(self, canvas, axes, *, useblit=True, horizOn=False, vertOn=True,
21092034

21102035
self.connect()
21112036

2112-
needclear=_api.deprecated("3.7")(lambdaself:False)
2113-
21142037
defconnect(self):
21152038
"""Connect events."""
21162039
forcanvas,infoinself._canvas_infos.items():
@@ -2613,8 +2536,7 @@ class SpanSelector(_SelectorWidget):
26132536
See also: :doc:`/gallery/widgets/span_selector`
26142537
"""
26152538

2616-
@_api.make_keyword_only("3.7",name="minspan")
2617-
def__init__(self,ax,onselect,direction,minspan=0,useblit=False,
2539+
def__init__(self,ax,onselect,direction,*,minspan=0,useblit=False,
26182540
props=None,onmove_callback=None,interactive=False,
26192541
button=None,handle_props=None,grab_range=10,
26202542
state_modifier_keys=None,drag_from_anywhere=False,
@@ -2957,8 +2879,7 @@ class ToolLineHandles:
29572879
for details.
29582880
"""
29592881

2960-
@_api.make_keyword_only("3.7","line_props")
2961-
def__init__(self,ax,positions,direction,line_props=None,
2882+
def__init__(self,ax,positions,direction,*,line_props=None,
29622883
useblit=True):
29632884
self.ax=ax
29642885

@@ -3068,8 +2989,7 @@ class ToolHandles:
30682989
for details.
30692990
"""
30702991

3071-
@_api.make_keyword_only("3.7","marker")
3072-
def__init__(self,ax,x,y,marker='o',marker_props=None,useblit=True):
2992+
def__init__(self,ax,x,y,*,marker='o',marker_props=None,useblit=True):
30732993
self.ax=ax
30742994
props= {'marker':marker,'markersize':7,'markerfacecolor':'w',
30752995
'linestyle':'none','alpha':0.5,'visible':False,
@@ -3771,8 +3691,7 @@ def onselect(verts):
37713691
which corresponds to all buttons.
37723692
"""
37733693

3774-
@_api.make_keyword_only("3.7",name="useblit")
3775-
def__init__(self,ax,onselect,useblit=True,props=None,button=None):
3694+
def__init__(self,ax,onselect,*,useblit=True,props=None,button=None):
37763695
super().__init__(ax,onselect,useblit=useblit,button=button)
37773696
self.verts=None
37783697
props= {
@@ -3882,9 +3801,8 @@ class PolygonSelector(_SelectorWidget):
38823801
point.
38833802
"""
38843803

3885-
@_api.make_keyword_only("3.7",name="useblit")
3886-
def__init__(self,ax,onselect,useblit=False,
3887-
props=None,handle_props=None,grab_range=10,*,
3804+
def__init__(self,ax,onselect,*,useblit=False,
3805+
props=None,handle_props=None,grab_range=10,
38883806
draw_bounding_box=False,box_handle_props=None,
38893807
box_props=None):
38903808
# The state modifiers 'move', 'square', and 'center' are expected by
@@ -4199,8 +4117,7 @@ class Lasso(AxesWidget):
41994117
for details.
42004118
"""
42014119

4202-
@_api.make_keyword_only("3.7",name="useblit")
4203-
def__init__(self,ax,xy,callback,useblit=True):
4120+
def__init__(self,ax,xy,callback,*,useblit=True):
42044121
super().__init__(ax)
42054122

42064123
self.useblit=useblitandself.canvas.supports_blit

‎lib/matplotlib/widgets.pyi

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ class CheckButtons(AxesWidget):
164164
defget_status(self)->list[bool]: ...
165165
defon_clicked(self,func:Callable[[str],Any])->int: ...
166166
defdisconnect(self,cid:int)->None: ...
167-
@property
168-
deflines(self)->list[tuple[Line2D,Line2D]]: ...
169-
@property
170-
defrectangles(self)->list[Rectangle]: ...
171167

172168
classTextBox(AxesWidget):
173169
label:Text
@@ -191,7 +187,7 @@ class TextBox(AxesWidget):
191187
@property
192188
deftext(self)->str: ...
193189
defset_val(self,val:str)->None: ...
194-
defbegin_typing(self,x= ...)->None: ...
190+
defbegin_typing(self)->None: ...
195191
defstop_typing(self)->None: ...
196192
defon_text_change(self,func:Callable[[str],Any])->int: ...
197193
defon_submit(self,func:Callable[[str],Any])->int: ...
@@ -217,8 +213,6 @@ class RadioButtons(AxesWidget):
217213
defset_active(self,index:int)->None: ...
218214
defon_clicked(self,func:Callable[[str],Any])->int: ...
219215
defdisconnect(self,cid:int)->None: ...
220-
@property
221-
defcircles(self)->list[Circle]: ...
222216

223217
classSubplotTool(Widget):
224218
figure:Figure
@@ -253,7 +247,6 @@ class MultiCursor(Widget):
253247
vertOn:bool
254248
visible:bool
255249
useblit:bool
256-
needclear:bool
257250
vlines:list[Line2D]
258251
hlines:list[Line2D]
259252
def__init__(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp