(key, mouseend, expectedxlim, expectedylim)
| 382 | ("control", (0.4, 0.2), (2.72, 11.72), (2.72, 11.72)), # diagonal |
| 383 | ]) |
| 384 | def test_interactive_pan(key, mouseend, expectedxlim, expectedylim): |
| 385 | fig, ax = plt.subplots() |
| 386 | ax.plot(np.arange(10)) |
| 387 | assert ax.get_navigate() |
| 388 | # Set equal aspect ratio to easier see diagonal snap |
| 389 | ax.set_aspect('equal') |
| 390 | |
| 391 | # Mouse move starts from 0.5, 0.5 |
| 392 | mousestart = (0.5, 0.5) |
| 393 | # Convert to screen coordinates ("s"). Events are defined only with pixel |
| 394 | # precision, so round the pixel values, and below, check against the |
| 395 | # corresponding xdata/ydata, which are close but not equal to d0/d1. |
| 396 | sstart = ax.transData.transform(mousestart).astype(int) |
| 397 | send = ax.transData.transform(mouseend).astype(int) |
| 398 | |
| 399 | # Set up the mouse movements |
| 400 | start_event = MouseEvent( |
| 401 | "button_press_event", fig.canvas, *sstart, button=MouseButton.LEFT, |
| 402 | key=key) |
| 403 | drag_event = MouseEvent( |
| 404 | "motion_notify_event", fig.canvas, *send, button=MouseButton.LEFT, |
| 405 | buttons={MouseButton.LEFT}, key=key) |
| 406 | stop_event = MouseEvent( |
| 407 | "button_release_event", fig.canvas, *send, button=MouseButton.LEFT, |
| 408 | key=key) |
| 409 | |
| 410 | tb = NavigationToolbar2(fig.canvas) |
| 411 | tb.pan() |
| 412 | tb.press_pan(start_event) |
| 413 | tb.drag_pan(drag_event) |
| 414 | tb.release_pan(stop_event) |
| 415 | # Should be close, but won't be exact due to screen integer resolution |
| 416 | assert tuple(ax.get_xlim()) == pytest.approx(expectedxlim, abs=0.02) |
| 417 | assert tuple(ax.get_ylim()) == pytest.approx(expectedylim, abs=0.02) |
| 418 | |
| 419 | |
| 420 | def test_toolmanager_remove(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…