|
4 | 4 |
|
5 | 5 | import itertools
|
6 | 6 | import timeit
|
| 7 | +from types import SimpleNamespace |
7 | 8 |
|
8 | 9 | from cycler import cycler
|
9 | 10 | import numpy as np
|
@@ -264,3 +265,29 @@ def test_marker_as_markerstyle():
|
264 | 265 | def test_odd_dashes(fig_test, fig_ref):
|
265 | 266 | fig_test.add_subplot().plot([1, 2], dashes=[1, 2, 3])
|
266 | 267 | 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