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

Commitba30bdf

Browse files
committed
Add tests to check .rectangles and .lines fallback
1 parent143cb9a commitba30bdf

File tree

3 files changed

+70
-26
lines changed

3 files changed

+70
-26
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
``CheckButtons``
2-
~~~~~~~~~~~~~~~~~~~~~~~~~
1+
``CheckButtons.rectangles`` and ``CheckButtons.lines``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33
``CheckButtons.rectangles`` and ``CheckButtons.lines`` are deprecated. (``CheckButtons`` now draws itself using `~.Axes.scatter`.)

‎lib/matplotlib/tests/test_widgets.py‎

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
importmatplotlib.colorsasmcolors
88
importmatplotlib.widgetsaswidgets
99
importmatplotlib.pyplotasplt
10+
frommatplotlib.patchesimportRectangle
11+
frommatplotlib.linesimportLine2D
1012
frommatplotlib.testing.decoratorsimportcheck_figures_equal,image_comparison
1113
frommatplotlib.testing.widgetsimport (click_and_drag,do_event,get_ax,
1214
mock_event,noop)
@@ -1009,8 +1011,7 @@ def test_check_radio_buttons_image():
10091011
cb=widgets.CheckButtons(rax2, ('Check 1','Check 2','Check 3'),
10101012
(False,True,True))
10111013
withpytest.warns(DeprecationWarning):
1012-
# Trigger old-style Rectangle check boxes
1013-
cb.rectangles
1014+
cb.rectangles# Trigger old-style Rectangle check boxes
10141015

10151016

10161017
@check_figures_equal(extensions=["png"])
@@ -1035,6 +1036,55 @@ def test_check_buttons(fig_test, fig_ref):
10351036
ax.text(.25,1/3,"coffee",transform=ax.transAxes,va="center")
10361037

10371038

1039+
@check_figures_equal(extensions=["png"])
1040+
deftest_check_buttons_rectangles(fig_test,fig_ref):
1041+
# Test should be removed once .rectangles is removed
1042+
cb=widgets.CheckButtons(fig_test.subplots(), ["",""],
1043+
[False,False])
1044+
withpytest.warns(DeprecationWarning):
1045+
cb.rectangles
1046+
ax=fig_ref.add_subplot(xticks=[],yticks=[])
1047+
ys= [2/3,1/3]
1048+
dy=1/3
1049+
w,h=dy/2,dy/2
1050+
rectangles= [
1051+
Rectangle(xy=(0.05,ys[i]-h/2),width=w,height=h,
1052+
edgecolor="black",
1053+
facecolor="none",
1054+
transform=ax.transAxes
1055+
)
1056+
fori,yinenumerate(ys)
1057+
]
1058+
forrectangleinrectangles:
1059+
ax.add_patch(rectangle)
1060+
1061+
1062+
@check_figures_equal(extensions=["png"])
1063+
deftest_check_buttons_lines(fig_test,fig_ref):
1064+
# Test should be removed once .lines is removed
1065+
cb=widgets.CheckButtons(fig_test.subplots(), ["",""], [True,True])
1066+
withpytest.warns(DeprecationWarning):
1067+
cb.lines
1068+
forrectangleincb._rectangles:
1069+
rectangle.set_visible(False)
1070+
ax=fig_ref.add_subplot(xticks=[],yticks=[])
1071+
ys= [2/3,1/3]
1072+
dy=1/3
1073+
w,h=dy/2,dy/2
1074+
lineparams= {'color':'k','linewidth':1.25,
1075+
'transform':ax.transAxes,
1076+
'solid_capstyle':'butt'}
1077+
fori,yinenumerate(ys):
1078+
x,y=0.05,y-h/2
1079+
l1=Line2D([x,x+w], [y+h,y],**lineparams)
1080+
l2=Line2D([x,x+w], [y,y+h],**lineparams)
1081+
1082+
l1.set_visible(True)
1083+
l2.set_visible(True)
1084+
ax.add_line(l1)
1085+
ax.add_line(l2)
1086+
1087+
10381088
deftest_slider_slidermin_slidermax_invalid():
10391089
fig,ax=plt.subplots()
10401090
# test min/max with floats

‎lib/matplotlib/widgets.py‎

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,13 +1012,11 @@ def __init__(self, ax, labels, actives=None):
10121012

10131013
self._squares=ax.scatter(
10141014
[0.15]*len(ys),ys,marker='s',s=text_size**2,
1015-
c=["none"for_inrange(len(ys))],
1016-
linewidth=1,transform=ax.transAxes,edgecolor="k"
1015+
c="none",linewidth=1,transform=ax.transAxes,edgecolor="k"
10171016
)
1018-
mask= [notxforxinactives]
10191017
self._crosses=ax.scatter(
10201018
[0.15]*len(ys),ys,marker='x',linewidth=1,s=text_size**2,
1021-
c=["k"ifactives[i]else"none"foriinrange(len(ys))],
1019+
c=["k"ifactiveelse"none"foractiveinactives],
10221020
transform=ax.transAxes
10231021
)
10241022

@@ -1030,22 +1028,19 @@ def _clicked(self, event):
10301028
ifself.ignore(event)orevent.button!=1orevent.inaxes!=self.ax:
10311029
return
10321030
pclicked=self.ax.transAxes.inverted().transform((event.x,event.y))
1033-
_,square_inds=self._squares.contains(event)
1034-
coords=self._squares.get_offset_transform().transform(
1035-
self._squares.get_offsets()
1036-
)
10371031
distances= {}
10381032
ifhasattr(self,"_rectangles"):
10391033
fori, (p,t)inenumerate(zip(self._rectangles,self.labels)):
1034+
x0,y0=p.get_xy()
10401035
if (t.get_window_extent().contains(event.x,event.y)
1041-
or (
1042-
p.get_x()<=pclicked[0]<=p.get_x()
1043-
+p.get_width()
1044-
andp.get_y()<=pclicked[1]<=p.get_y()
1045-
+p.get_height()
1046-
)):
1036+
or (x0<=pclicked[0]<=x0+p.get_width()
1037+
andy0<=pclicked[1]<=y0+p.get_height())):
10471038
distances[i]=np.linalg.norm(pclicked-p.get_center())
10481039
else:
1040+
_,square_inds=self._squares.contains(event)
1041+
coords=self._squares.get_offset_transform().transform(
1042+
self._squares.get_offsets()
1043+
)
10491044
fori,tinenumerate(self.labels):
10501045
if (iinsquare_inds["ind"]
10511046
ort.get_window_extent().contains(event.x,event.y)):
@@ -1074,12 +1069,12 @@ def set_active(self, index):
10741069
raiseValueError(f'Invalid CheckButton index:{index}')
10751070

10761071
cross_facecolors=self._crosses.get_facecolor()
1077-
cross_facecolors[index]= (
1078-
colors.to_rgba("black")
1072+
cross_facecolors[index]=colors.to_rgba(
1073+
"black"
10791074
ifcolors.same_color(
1080-
cross_facecolors[index],colors.to_rgba("none")
1075+
cross_facecolors[index],colors.to_rgba("none")
10811076
)
1082-
elsecolors.to_rgba("none")
1077+
else"none"
10831078
)
10841079
self._crosses.set_facecolor(cross_facecolors)
10851080

@@ -1098,9 +1093,8 @@ def get_status(self):
10981093
"""
10991094
Return a tuple of the status (True/False) of all of the check buttons.
11001095
"""
1101-
return [Falseifcolors.same_color(
1102-
self._crosses.get_facecolors()[i],colors.to_rgba("none"))
1103-
elseTrueforiinrange(len(self.labels))]
1096+
return [notcolors.same_color(color,colors.to_rgba("none"))
1097+
forcolorinself._crosses.get_facecolors()]
11041098

11051099
defon_clicked(self,func):
11061100
"""
@@ -1124,7 +1118,7 @@ def rectangles(self):
11241118
rectangles=self._rectangles= [
11251119
Rectangle(xy=(0.05,ys[i]-h/2),width=w,height=h,
11261120
edgecolor="black",
1127-
facecolor=self._squares.get_facecolor()[i],
1121+
facecolor="none",
11281122
transform=self.ax.transAxes
11291123
)
11301124
fori,yinenumerate(ys)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp