MCPcopy
hub / github.com/matplotlib/matplotlib / test_span_selector

Function test_span_selector

lib/matplotlib/tests/test_widgets.py:635–665  ·  view source on GitHub ↗
(ax, orientation, onmove_callback, kwargs)

Source from the content-addressed store, hash-verified

633 ('horizontal', False, dict(interactive=True)),
634])
635def test_span_selector(ax, orientation, onmove_callback, kwargs):
636 # Also test that span selectors work in the presence of twin axes or for
637 # outside-inset axes on top of the axes that contain the selector. Note
638 # that we need to unforce the axes aspect here, otherwise the twin axes
639 # forces the original axes' limits (to respect aspect=1) which makes some
640 # of the values below go out of bounds.
641 ax.set_aspect("auto")
642 ax.twinx()
643 child = ax.inset_axes([0, 1, 1, 1], xlim=(0, 200), ylim=(0, 200))
644
645 for target in [ax, child]:
646 selected = []
647 def onselect(*args): selected.append(args)
648 moved = []
649 def onmove(*args): moved.append(args)
650 if onmove_callback:
651 kwargs['onmove_callback'] = onmove
652
653 tool = widgets.SpanSelector(target, onselect, orientation, **kwargs)
654 MouseEvent._from_ax_coords(
655 "button_press_event", target, (100, 100), 1)._process()
656 # move outside of axis
657 MouseEvent._from_ax_coords(
658 "motion_notify_event", target, (199, 199), 1)._process()
659 MouseEvent._from_ax_coords(
660 "button_release_event", target, (250, 250), 1)._process()
661
662 # tol is set by pixel size (~100 pixels & span of 200 data units)
663 assert_allclose(selected, [(100, 199)], atol=.5)
664 if onmove_callback:
665 assert_allclose(moved, [(100, 199)], atol=.5)
666
667
668@pytest.mark.parametrize('interactive', [True, False])

Callers

nothing calls this directly

Calls 5

inset_axesMethod · 0.80
_processMethod · 0.80
set_aspectMethod · 0.45
twinxMethod · 0.45
_from_ax_coordsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…