()
| 343 | |
| 344 | |
| 345 | def test_cursor_data(): |
| 346 | from matplotlib.backend_bases import MouseEvent |
| 347 | |
| 348 | fig, ax = plt.subplots() |
| 349 | im = ax.imshow(np.arange(100).reshape(10, 10), origin='upper') |
| 350 | |
| 351 | x, y = 4, 4 |
| 352 | xdisp, ydisp = ax.transData.transform([x, y]) |
| 353 | |
| 354 | event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) |
| 355 | assert im.get_cursor_data(event) == 44 |
| 356 | |
| 357 | # Now try for a point outside the image |
| 358 | # Tests issue #4957 |
| 359 | x, y = 10.1, 4 |
| 360 | xdisp, ydisp = ax.transData.transform([x, y]) |
| 361 | |
| 362 | event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) |
| 363 | assert im.get_cursor_data(event) is None |
| 364 | |
| 365 | # Hmm, something is wrong here... I get 0, not None... |
| 366 | # But, this works further down in the tests with extents flipped |
| 367 | # x, y = 0.1, -0.1 |
| 368 | # xdisp, ydisp = ax.transData.transform([x, y]) |
| 369 | # event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) |
| 370 | # z = im.get_cursor_data(event) |
| 371 | # assert z is None, "Did not get None, got %d" % z |
| 372 | |
| 373 | ax.clear() |
| 374 | # Now try with the extents flipped. |
| 375 | im = ax.imshow(np.arange(100).reshape(10, 10), origin='lower') |
| 376 | |
| 377 | x, y = 4, 4 |
| 378 | xdisp, ydisp = ax.transData.transform([x, y]) |
| 379 | |
| 380 | event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) |
| 381 | assert im.get_cursor_data(event) == 44 |
| 382 | |
| 383 | fig, ax = plt.subplots() |
| 384 | im = ax.imshow(np.arange(100).reshape(10, 10), extent=[0, 0.5, 0, 0.5]) |
| 385 | |
| 386 | x, y = 0.25, 0.25 |
| 387 | xdisp, ydisp = ax.transData.transform([x, y]) |
| 388 | |
| 389 | event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) |
| 390 | assert im.get_cursor_data(event) == 55 |
| 391 | |
| 392 | # Now try for a point outside the image |
| 393 | # Tests issue #4957 |
| 394 | x, y = 0.75, 0.25 |
| 395 | xdisp, ydisp = ax.transData.transform([x, y]) |
| 396 | |
| 397 | event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) |
| 398 | assert im.get_cursor_data(event) is None |
| 399 | |
| 400 | x, y = 0.01, -0.01 |
| 401 | xdisp, ydisp = ax.transData.transform([x, y]) |
| 402 |
nothing calls this directly
no test coverage detected
searching dependent graphs…