Skip to content

Let widgets/clabel better handle overlapping axes. #25555

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

Merged
merged 1 commit into from
Jun 13, 2023
Merged
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
2 changes: 1 addition & 1 deletion lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _contour_labeler_event_handler(cs, inline, inline_spacing, event):
elif (is_button and event.button == MouseButton.LEFT
# On macOS/gtk, some keys return None.
or is_key and event.key is not None):
if event.inaxes == cs.axes:
if cs.axes.contains(event)[0]:
cs.add_label_near(event.x, event.y, transform=False,
inline=inline, inline_spacing=inline_spacing)
canvas.draw()
Expand Down
14 changes: 11 additions & 3 deletions lib/matplotlib/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,13 @@ def test_span_selector(ax, orientation, onmove_callback, kwargs):
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.
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
Expand Down Expand Up @@ -925,7 +932,7 @@ def mean(vmin, vmax):

# Change span selector and check that the line is drawn/updated after its
# value was updated by the callback
press_data = [4, 2]
press_data = [4, 0]
move_data = [5, 2]
release_data = [5, 2]
do_event(span, 'press', xdata=press_data[0], ydata=press_data[1], button=1)
Expand Down Expand Up @@ -1033,7 +1040,7 @@ def test_TextBox(ax, toolbar):

assert submit_event.call_count == 2

do_event(tool, '_click')
do_event(tool, '_click', xdata=.5, ydata=.5) # Ensure the click is in the axes.
do_event(tool, '_keypress', key='+')
do_event(tool, '_keypress', key='5')

Expand Down Expand Up @@ -1632,7 +1639,8 @@ def test_polygon_selector_verts_setter(fig_test, fig_ref, draw_bounding_box):


def test_polygon_selector_box(ax):
# Create a diamond shape
# Create a diamond (adjusting axes lims s.t. the diamond lies within axes limits).
ax.set(xlim=(-10, 50), ylim=(-10, 50))
verts = [(20, 0), (0, 20), (20, 40), (40, 20)]
event_sequence = [
*polygon_place_vertex(*verts[0]),
Expand Down
Loading