@@ -93,6 +93,7 @@ def __init__(self,
9393 self .set_linewidth (linewidths )
9494 self .set_linestyle (linestyles )
9595 self .set_antialiased (antialiaseds )
96+ self .set_pickradius (pickradius )
9697 self .set_urls (urls )
9798
9899
@@ -109,7 +110,6 @@ def __init__(self,
109110 else :
110111 self ._uniform_offsets = offsets
111112
112- self ._pickradius = pickradius
113113 self .update (kwargs )
114114 self ._paths = None
115115
@@ -232,26 +232,48 @@ def draw(self, renderer):
232232 gc .restore ()
233233 renderer .close_group (self .__class__ .__name__ )
234234
235+ def set_pickradius (self , pr ):
236+ self ._pickradius = pr
237+
238+ def get_pickradius (self ):
239+ return self ._pickradius
240+
235241 def contains (self , mouseevent ):
236242 """
237243 Test whether the mouse event occurred in the collection.
238244
239245 Returns True | False, ``dict(ind=itemlist)``, where every
240246 item in itemlist contains the event.
241247 """
242- if callable (self ._contains ): return self ._contains (self ,mouseevent )
243- if not self .get_visible (): return False ,{}
248+ if callable (self ._contains ):
249+ return self ._contains (self ,mouseevent )
250+
251+ if not self .get_visible ():
252+ return False , {}
253+
254+ if self ._picker is True : # the Boolean constant, not just nonzero or 1
255+ pickradius = self ._pickradius
256+ else :
257+ try :
258+ pickradius = float (self ._picker )
259+ except TypeError :
260+ # This should not happen if "contains" is called via
261+ # pick, the normal route; the check is here in case
262+ # it is called through some unanticipated route.
263+ warnings .warn (
264+ "Collection picker %s could not be converted to float"
265+ % self ._picker )
266+ pickradius = self ._pickradius
244267
245268 transform , transOffset , offsets , paths = self ._prepare_points ()
246269
247270 ind = mpath .point_in_path_collection (
248- mouseevent .x , mouseevent .y , self . _pickradius ,
271+ mouseevent .x , mouseevent .y , pickradius ,
249272 transform .frozen (), paths , self .get_transforms (),
250- offsets , transOffset , len (self ._facecolors )> 0 )
251- return len (ind )> 0 ,dict (ind = ind )
273+ offsets , transOffset , pickradius <= 0 )
274+
275+ return len (ind )> 0 , dict (ind = ind )
252276
253- def set_pickradius (self ,pickradius ): self .pickradius = 5
254- def get_pickradius (self ): return self .pickradius
255277
256278 def set_urls (self , urls ):
257279 if urls is None :
0 commit comments