@@ -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 _ in range (len (ys ))],
1016- linewidth = 1 , transform = ax .transAxes , edgecolor = "k"
1015+ c = "none" , linewidth = 1 , transform = ax .transAxes , edgecolor = "k"
10171016 )
1018- mask = [not x for x in actives ]
10191017 self ._crosses = ax .scatter (
10201018 [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 ],
10221020 transform = ax .transAxes
10231021 )
10241022
@@ -1030,22 +1028,19 @@ def _clicked(self, event):
10301028 if self .ignore (event ) or event .button != 1 or event .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 if hasattr (self , "_rectangles" ):
10391033 for i , (p , t ) in enumerate (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- 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 ())):
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 for i , t in enumerate (self .labels ):
10501045 if (i in square_inds ["ind" ]
10511046 or t .get_window_extent ().contains (event .x , event .y )):
@@ -1074,12 +1069,12 @@ def set_active(self, index):
10741069 raise ValueError (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 if colors .same_color (
10801075 cross_facecolors [index ], colors .to_rgba ("none" )
10811076 )
1082- else colors . 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 [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 ()]
11041098
11051099 def on_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 for i , y in enumerate (ys )
0 commit comments