Skip to content

Fix AxesWidgets on inset_axes that are outside their parent. #29966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions lib/matplotlib/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,27 +623,30 @@ def test_rectangle_selector_ignore_outside(ax, ignore_event_outside):
('horizontal', False, dict(interactive=True)),
])
def test_span_selector(ax, orientation, onmove_callback, kwargs):
onselect = mock.Mock(spec=noop, return_value=None)
onmove = mock.Mock(spec=noop, return_value=None)
if onmove_callback:
kwargs['onmove_callback'] = onmove

# While at it, also test that span selectors work in the presence of twin axes on
# top of the axes that contain the selector. Note that we need to unforce the axes
# aspect here, otherwise the twin axes forces the original axes' limits (to respect
# aspect=1) which makes some of the values below go out of bounds.
# Also test that span selectors work in the presence of twin axes or for
# outside-inset axes on top of the axes that contain the selector. Note
# that we need to unforce the axes aspect here, otherwise the twin axes
# forces the original axes' limits (to respect aspect=1) which makes some
# of the values below go out of bounds.
ax.set_aspect("auto")
tax = ax.twinx()

tool = widgets.SpanSelector(ax, onselect, orientation, **kwargs)
do_event(tool, 'press', xdata=100, ydata=100, button=1)
# move outside of axis
do_event(tool, 'onmove', xdata=199, ydata=199, button=1)
do_event(tool, 'release', xdata=250, ydata=250, button=1)

onselect.assert_called_once_with(100, 199)
if onmove_callback:
onmove.assert_called_once_with(100, 199)
ax.twinx()
child = ax.inset_axes([0, 1, 1, .05], xlim=(0, 200), ylim=(0, 200))

for target in [ax, child]:
onselect = mock.Mock(spec=noop, return_value=None)
onmove = mock.Mock(spec=noop, return_value=None)
if onmove_callback:
kwargs['onmove_callback'] = onmove

tool = widgets.SpanSelector(target, onselect, orientation, **kwargs)
do_event(tool, 'press', xdata=100, ydata=100, button=1)
# move outside of axis
do_event(tool, 'onmove', xdata=199, ydata=199, button=1)
do_event(tool, 'release', xdata=250, ydata=250, button=1)

onselect.assert_called_once_with(100, 199)
if onmove_callback:
onmove.assert_called_once_with(100, 199)


@pytest.mark.parametrize('interactive', [True, False])
Expand Down
Loading
Loading