@@ -1011,7 +1011,8 @@ def __init__(self, ax, labels, actives=None):
10111011 for y , label in zip (ys , labels )]
10121012
10131013 self ._squares = ax .scatter (
1014- [0.15 ] * len (ys ), ys , marker = 's' , c = "none" , s = text_size ** 2 ,
1014+ [0.15 ] * len (ys ), ys , marker = 's' , s = text_size ** 2 ,
1015+ c = ["none" for _ in range (len (ys ))],
10151016 linewidth = 1 , transform = ax .transAxes , edgecolor = "k"
10161017 )
10171018 mask = [not x for x in actives ]
@@ -1038,8 +1039,9 @@ def _clicked(self, event):
10381039 for i , (p , t ) in enumerate (zip (self ._rectangles , self .labels )):
10391040 if (t .get_window_extent ().contains (event .x , event .y )
10401041 or (
1041- p .get_x () < event .x < p .get_x () + p .get_width ()
1042- and p .get_y () < event .y < p .get_y ()
1042+ p .get_x () <= pclicked [0 ] <= p .get_x ()
1043+ + p .get_width ()
1044+ and p .get_y () <= pclicked [1 ] <= p .get_y ()
10431045 + p .get_height ()
10441046 )):
10451047 distances [i ] = np .linalg .norm (pclicked - p .get_center ())
@@ -1081,11 +1083,10 @@ def set_active(self, index):
10811083 )
10821084 self ._crosses .set_facecolor (cross_facecolors )
10831085
1084- if hasattr (self , "_rectangles" ):
1085- for i , p in enumerate (self ._rectangles ):
1086- p .set_facecolor ("k" if colors .same_color (
1087- p .get_facecolor (), colors .to_rgba ("none" ))
1088- else "none" )
1086+ if hasattr (self , "_lines" ):
1087+ l1 , l2 = self ._lines [index ]
1088+ l1 .set_visible (not l1 .get_visible ())
1089+ l2 .set_visible (not l2 .get_visible ())
10891090
10901091 if self .drawon :
10911092 self .ax .figure .canvas .draw ()
@@ -1113,24 +1114,51 @@ def disconnect(self, cid):
11131114 """Remove the observer with connection id *cid*."""
11141115 self ._observers .disconnect (cid )
11151116
1117+ @_api .deprecated ("3.7" )
11161118 @property
11171119 def rectangles (self ):
1118- if not hasattr (self , "rectangles" ):
1120+ if not hasattr (self , "_rectangles" ):
1121+ ys = np .linspace (1 , 0 , len (self .labels )+ 2 )[1 :- 1 ]
11191122 dy = 1. / (len (self .labels ) + 1 )
11201123 w , h = dy / 2 , dy / 2
11211124 rectangles = self ._rectangles = [
1122- Rectangle (xy = self . _squares . get_offsets () [i ], width = w , height = h ,
1125+ Rectangle (xy = ( 0.05 , ys [i ] - h / 2 ) , width = w , height = h ,
11231126 edgecolor = "black" ,
11241127 facecolor = self ._squares .get_facecolor ()[i ],
11251128 transform = self .ax .transAxes
11261129 )
1127- for i in range ( len ( self . labels ) )
1130+ for i , y in enumerate ( ys )
11281131 ]
11291132 self ._squares .set_visible (False )
11301133 for rectangle in rectangles :
11311134 self .ax .add_patch (rectangle )
11321135 return self ._rectangles
11331136
1137+ @_api .deprecated ("3.7" )
1138+ @property
1139+ def lines (self ):
1140+ if not hasattr (self , "_lines" ):
1141+ ys = np .linspace (1 , 0 , len (self .labels )+ 2 )[1 :- 1 ]
1142+ self ._crosses .set_visible (False )
1143+ dy = 1. / (len (self .labels ) + 1 )
1144+ w , h = dy / 2 , dy / 2
1145+ self ._lines = []
1146+ current_status = self .get_status ()
1147+ lineparams = {'color' : 'k' , 'linewidth' : 1.25 ,
1148+ 'transform' : self .ax .transAxes ,
1149+ 'solid_capstyle' : 'butt' }
1150+ for i , y in enumerate (ys ):
1151+ x , y = 0.05 , y - h / 2
1152+ l1 = Line2D ([x , x + w ], [y + h , y ], ** lineparams )
1153+ l2 = Line2D ([x , x + w ], [y , y + h ], ** lineparams )
1154+
1155+ l1 .set_visible (current_status [i ])
1156+ l2 .set_visible (current_status [i ])
1157+ self ._lines .append ((l1 , l2 ))
1158+ self .ax .add_patch (l1 )
1159+ self .ax .add_patch (l2 )
1160+ return self ._lines
1161+
11341162
11351163class TextBox (AxesWidget ):
11361164 """
0 commit comments