8000 Don't warn in Collections.contains if picker is not numlike. · matplotlib/matplotlib@c5ec5b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit c5ec5b3

Browse files
committed
Don't warn in Collections.contains if picker is not numlike.
Otherwise, a warning is raised in the simple example: from pylab import * def pick_test(artist, mouseevent): return coll.contains(mouseevent) coll = plt.scatter([0, 1], [0, 1], picker=pick_test) plt.show() (Click anywhere in the figure to trigger the warning.) The use of `is_numlike` matches the implementation of `Line2D.contains`. Initially noted while using mpldatacursor.
1 parent f16308a commit c5ec5b3

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

lib/matplotlib/collections.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
except ImportError:
1919
# LPy workaround
2020
from fractions import gcd
21-
import warnings
2221

2322
import numpy as np
2423
import matplotlib as mpl
@@ -363,19 +362,11 @@ def contains(self, mouseevent):
363362
if not self.get_visible():
364363
return False, {}
365364

366-
if self._picker is True: # the Boolean constant, not just nonzero or 1
367-
pickradius = self._pickradius
368-
else:
369-
try:
370-
pickradius = float(self._picker)
371-
except TypeError:
372-
# This should not happen if "contains" is called via
373-
# pick, the normal route; the check is here in case
374-
# it is called through some unanticipated route.
375-
warnings.warn(
376-
"Collection picker %s could not be converted to float"
377-
% self._picker)
378-
pickradius = self._pickradius
365+
pickradius = (
366+
float(self._picker)
367+
if cbook.is_numlike(self._picker) and
368+
self._picker is not True # the bool, not just nonzero or 1
369+
else self._pickradius)
379370

380371
transform, transOffset, offsets, paths = self._prepare_points()
381372

0 commit comments

Comments
 (0)
0