8000 Merge pull request #19742 from meeseeksmachine/auto-backport-of-pr-19… · matplotlib/matplotlib@8d72bd3 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8d72bd3

Browse files
authored
Merge pull request #19742 from meeseeksmachine/auto-backport-of-pr-19741-on-v3.4.x
Backport PR #19741 on branch v3.4.x (Only override pickradius when picker is not a bool.)
2 parents 878db27 + d687d0f commit 8d72bd3

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/matplotlib/lines.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ def __init__(self, xdata, ydata,
397397
self.update(kwargs)
398398
self.pickradius = pickradius
399399
self.ind_offset = 0
400-
if isinstance(self._picker, Number):
400+
if (isinstance(self._picker, Number) and
401+
not isinstance(self._picker, bool)):
401402
self.pickradius = self._picker
402403

403404
self._xorig = np.asarray([])

lib/matplotlib/tests/test_lines.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import itertools
66
import timeit
7+
from types import SimpleNamespace
78

89
from cycler import cycler
910
import numpy as np
@@ -264,3 +265,29 @@ def test_marker_as_markerstyle():
264265
def test_odd_dashes(fig_test, fig_ref):
265266
fig_test.add_subplot().plot([1, 2], dashes=[1, 2, 3])
266267
fig_ref.add_subplot().plot([1, 2], dashes=[1, 2, 3, 1, 2, 3])
268+
269+
270+
def test_picking():
271+
fig, ax = plt.subplots()
272+
mouse_event = SimpleNamespace(x=fig.bbox.width // 2,
273+
y=fig.bbox.height // 2 + 15)
274+
275+
# Default pickradius is 5, so event should not pick this line.
276+
l0, = ax.plot([0, 1], [0, 1], picker=True)
277+
found, indices = l0.contains(mouse_event)
278+
assert not found
279+
280+
# But with a larger pickradius, this should be picked.
281+
l1, = ax.plot([0, 1], [0, 1], picker=True, pickradius=20)
282+
found, indices = l1.contains(mouse_event)
283+
assert found
284+
assert_array_equal(indices['ind'], [0])
285+
286+
# And if we modify the pickradius after creation, it should work as well.
287+
l2, = ax.plot([0, 1], [0, 1], picker=True)
288+
found, indices = l2.contains(mouse_event)
289+
assert not found
290+
l2.set_pickradius(20)
291+
found, indices = l2.contains(mouse_event)
292+
assert found
293+
assert_array_equal(indices['ind'], [0])

0 commit comments

Comments
 (0)
0