@@ -1011,7 +1011,8 @@ def __init__(self, ax, labels, actives=None):
1011
1011
for y , label in zip (ys , labels )]
1012
1012
1013
1013
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 ))],
1015
1016
linewidth = 1 , transform = ax .transAxes , edgecolor = "k"
1016
1017
)
1017
1018
mask = [not x for x in actives ]
@@ -1038,8 +1039,9 @@ def _clicked(self, event):
1038
1039
for i , (p , t ) in enumerate (zip (self ._rectangles , self .labels )):
1039
1040
if (t .get_window_extent ().contains (event .x , event .y )
1040
1041
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 ()
1043
1045
+ p .get_height ()
1044
1046
)):
1045
1047
distances [i ] = np .linalg .norm (pclicked - p .get_center ())
@@ -1081,11 +1083,10 @@ def set_active(self, index):
1081
1083
)
1082
1084
self ._crosses .set_facecolor (cross_facecolors )
1083
1085
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 ())
1089
1090
1090
1091
if self .drawon :
1091
1092
self .ax .figure .canvas .draw ()
@@ -1113,24 +1114,51 @@ def disconnect(self, cid):
1113
1114
"""Remove the observer with connection id *cid*."""
1114
1115
self ._observers .disconnect (cid )
1115
1116
1117
+ @_api .deprecated ("3.7" )
1116
1118
@property
1117
1119
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 ]
1119
1122
dy = 1. / (len (self .labels ) + 1 )
1120
1123
w , h = dy / 2 , dy / 2
1121
1124
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 ,
1123
1126
edgecolor = "black" ,
1124
1127
facecolor = self ._squares .get_facecolor ()[i ],
1125
1128
transform = self .ax .transAxes
1126
1129
)
1127
- for i in range ( len ( self . labels ) )
1130
+ for i , y in enumerate ( ys )
1128
1131
]
1129
1132
self ._squares .set_visible (False )
1130
1133
for rectangle in rectangles :
1131
1134
self .ax .add_patch (rectangle )
1132
1135
return self ._rectangles
1133
1136
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
+
1134
1162
1135
1163
class TextBox (AxesWidget ):
1136
1164
"""
0 commit comments