Skip to content

Commit 9eb10ef

Browse files
committed
Bugfix: enable picking of AsteriskCollection instances
A primary use of these is in scatter, where they provide + and x symbols.
1 parent fb78581 commit 9eb10ef

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2011-04-03 Fixed broken pick interface to AsteriskCollection objects
2+
used by scatter. - EF
3+
14
2011-03-29 Wrapped ViewVCCachedServer definition in a factory function.
25
This class now inherits from urllib2.HTTPSHandler in order
36
to fetch data from github, but HTTPSHandler is not defined

lib/matplotlib/collections.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def __init__(self,
9090
self.set_linewidth(linewidths)
9191
self.set_linestyle(linestyles)
9292
self.set_antialiased(antialiaseds)
93+
self.set_pickradius(pickradius)
9394
self.set_urls(urls)
9495

9596

@@ -105,7 +106,6 @@ def __init__(self,
105106
else:
106107
self._uniform_offsets = offsets
107108

108-
self._pickradius = pickradius
109109
self.update(kwargs)
110110
self._paths = None
111111

@@ -221,26 +221,48 @@ def draw(self, renderer):
221221
gc.restore()
222222
renderer.close_group(self.__class__.__name__)
223223

224+
def set_pickradius(self, pr):
225+
self._pickradius = pr
226+
227+
def get_pickradius(self):
228+
return self._pickradius
229+
224230
def contains(self, mouseevent):
225231
"""
226232
Test whether the mouse event occurred in the collection.
227233
228234
Returns True | False, ``dict(ind=itemlist)``, where every
229235
item in itemlist contains the event.
230236
"""
231-
if callable(self._contains): return self._contains(self,mouseevent)
232-
if not self.get_visible(): return False,{}
237+
if callable(self._contains):
238+
return self._contains(self,mouseevent)
239+
240+
if not self.get_visible():
241+
return False, {}
242+
243+
if self._picker is True: # the Boolean constant, not just nonzero or 1
244+
pickradius = self._pickradius
245+
else:
246+
try:
247+
pickradius = float(self._picker)
248+
except TypeError:
249+
# This should not happen if "contains" is called via
250+
# pick, the normal route; the check is here in case
251+
# it is called through some unanticipated route.
252+
warnings.warn(
253+
"Collection picker %s could not be converted to float"
254+
% self._picker)
255+
pickradius = self._pickradius
233256

234257
transform, transOffset, offsets, paths = self._prepare_points()
235258

236259
ind = mpath.point_in_path_collection(
237-
mouseevent.x, mouseevent.y, self._pickradius,
260+
mouseevent.x, mouseevent.y, pickradius,
238261
transform.frozen(), paths, self.get_transforms(),
239-
offsets, transOffset, len(self._facecolors)>0)
240-
return len(ind)>0,dict(ind=ind)
262+
offsets, transOffset, pickradius <= 0)
263+
264+
return len(ind)>0, dict(ind=ind)
241265

242-
def set_pickradius(self,pickradius): self.pickradius = 5
243-
def get_pickradius(self): return self.pickradius
244266

245267
def set_urls(self, urls):
246268
if urls is None:

0 commit comments

Comments
 (0)