MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_picking

Function test_picking

lib/matplotlib/tests/test_lines.py:311–334  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

309
310
311def test_picking():
312 fig, ax = plt.subplots()
313 mouse_event = SimpleNamespace(x=fig.bbox.width // 2,
314 y=fig.bbox.height // 2 + 15)
315
316 # Default pickradius is 5, so event should not pick this line.
317 l0, = ax.plot([0, 1], [0, 1], picker=True)
318 found, indices = l0.contains(mouse_event)
319 assert not found
320
321 # But with a larger pickradius, this should be picked.
322 l1, = ax.plot([0, 1], [0, 1], picker=True, pickradius=20)
323 found, indices = l1.contains(mouse_event)
324 assert found
325 assert_array_equal(indices['ind'], [0])
326
327 # And if we modify the pickradius after creation, it should work as well.
328 l2, = ax.plot([0, 1], [0, 1], picker=True)
329 found, indices = l2.contains(mouse_event)
330 assert not found
331 l2.set_pickradius(20)
332 found, indices = l2.contains(mouse_event)
333 assert found
334 assert_array_equal(indices['ind'], [0])
335
336
337@check_figures_equal()

Callers

nothing calls this directly

Calls 4

subplotsMethod · 0.45
plotMethod · 0.45
containsMethod · 0.45
set_pickradiusMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…