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

Function test_interactive_pan

lib/matplotlib/tests/test_backend_bases.py:384–417  ·  view source on GitHub ↗
(key, mouseend, expectedxlim, expectedylim)

Source from the content-addressed store, hash-verified

382 ("control", (0.4, 0.2), (2.72, 11.72), (2.72, 11.72)), # diagonal
383 ])
384def 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
420def test_toolmanager_remove():

Callers

nothing calls this directly

Calls 13

panMethod · 0.95
press_panMethod · 0.95
drag_panMethod · 0.95
release_panMethod · 0.95
MouseEventClass · 0.90
NavigationToolbar2Class · 0.90
get_navigateMethod · 0.80
subplotsMethod · 0.45
plotMethod · 0.45
set_aspectMethod · 0.45
transformMethod · 0.45
get_xlimMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…