@@ -1012,13 +1012,11 @@ def __init__(self, ax, labels, actives=None):
1012
1012
1013
1013
self ._squares = ax .scatter (
1014
1014
[0.15 ] * len (ys ), ys , marker = 's' , s = text_size ** 2 ,
1015
- c = ["none" for _ in range (len (ys ))],
1016
- linewidth = 1 , transform = ax .transAxes , edgecolor = "k"
1015
+ c = "none" , linewidth = 1 , transform = ax .transAxes , edgecolor = "k"
1017
1016
)
1018
- mask = [not x for x in actives ]
1019
1017
self ._crosses = ax .scatter (
1020
1018
[0.15 ] * len (ys ), ys , marker = 'x' , linewidth = 1 , s = text_size ** 2 ,
1021
- c = ["k" if actives [ i ] else "none" for i in range ( len ( ys )) ],
1019
+ c = ["k" if active else "none" for active in actives ],
1022
1020
transform = ax .transAxes
1023
1021
)
1024
1022
@@ -1030,22 +1028,19 @@ def _clicked(self, event):
1030
1028
if self .ignore (event ) or event .button != 1 or event .inaxes != self .ax :
1031
1029
return
1032
1030
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
- )
1037
1031
distances = {}
1038
1032
if hasattr (self , "_rectangles" ):
1039
1033
for i , (p , t ) in enumerate (zip (self ._rectangles , self .labels )):
1034
+ x0 , y0 = p .get_xy ()
1040
1035
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
- and p .get_y () <= pclicked [1 ] <= p .get_y ()
1045
- + p .get_height ()
1046
- )):
1036
+ or (x0 <= pclicked [0 ] <= x0 + p .get_width ()
1037
+ and y0 <= pclicked [1 ] <= y0 + p .get_height ())):
1047
1038
distances [i ] = np .linalg .norm (pclicked - p .get_center ())
1048
1039
else :
1040
+ _ , square_inds = self ._squares .contains (event )
1041
+ coords = self ._squares .get_offset_transform ().transform (
1042
+ self ._squares .get_offsets ()
1043
+ )
1049
1044
for i , t in enumerate (self .labels ):
1050
1045
if (i in square_inds ["ind" ]
1051
1046
or t .get_window_extent ().contains (event .x , event .y )):
@@ -1074,12 +1069,12 @@ def set_active(self, index):
1074
1069
raise ValueError (f'Invalid CheckButton index: { index } ' )
1075
1070
1076
1071
cross_facecolors = self ._crosses .get_facecolor ()
1077
- cross_facecolors [index ] = (
1078
- colors . to_rgba ( "black" )
1072
+ cross_facecolors [index ] = colors . to_rgba (
1073
+ "black"
1079
1074
if colors .same_color (
1080
- cross_facecolors [index ], colors .to_rgba ("none" )
1075
+ cross_facecolors [index ], colors .to_rgba ("none" )
1081
1076
)
1082
- else colors . to_rgba ( "none" )
1077
+ else "none"
1083
1078
)
1084
1079
self ._crosses .set_facecolor (cross_facecolors )
1085
1080
@@ -1098,9 +1093,8 @@ def get_status(self):
1098
1093
"""
1099
1094
Return a tuple of the status (True/False) of all of the check buttons.
1100
1095
"""
1101
- return [False if colors .same_color (
1102
- self ._crosses .get_facecolors ()[i ], colors .to_rgba ("none" ))
1103
- else True for i in range (len (self .labels ))]
1096
+ return [not colors .same_color (color , colors .to_rgba ("none" ))
1097
+ for color in self ._crosses .get_facecolors ()]
1104
1098
1105
1099
def on_clicked (self , func ):
1106
1100
"""
@@ -1124,7 +1118,7 @@ def rectangles(self):
1124
1118
rectangles = self ._rectangles = [
1125
1119
Rectangle (xy = (0.05 , ys [i ] - h / 2 ), width = w , height = h ,
1126
1120
edgecolor = "black" ,
1127
- facecolor = self . _squares . get_facecolor ()[ i ] ,
1121
+ facecolor = "none" ,
1128
1122
transform = self .ax .transAxes
1129
1123
)
1130
1124
for i , y in enumerate (ys )
0 commit comments