Skip to content

Commit 94edf8a

Browse files
authored
Merge pull request #25555 from anntzer/wia
Let widgets/clabel better handle overlapping axes.
2 parents 3c597f6 + 8bab597 commit 94edf8a

File tree

3 files changed

+110
-103
lines changed

3 files changed

+110
-103
lines changed

lib/matplotlib/contour.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _contour_labeler_event_handler(cs, inline, inline_spacing, event):
6868
elif (is_button and event.button == MouseButton.LEFT
6969
# On macOS/gtk, some keys return None.
7070
or is_key and event.key is not None):
71-
if event.inaxes == cs.axes:
71+
if cs.axes.contains(event)[0]:
7272
cs.add_label_near(event.x, event.y, transform=False,
7373
inline=inline, inline_spacing=inline_spacing)
7474
canvas.draw()

lib/matplotlib/tests/test_widgets.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,13 @@ def test_span_selector(ax, orientation, onmove_callback, kwargs):
643643
if onmove_callback:
644644
kwargs['onmove_callback'] = onmove
645645

646+
# While at it, also test that span selectors work in the presence of twin axes on
647+
# top of the axes that contain the selector. Note that we need to unforce the axes
648+
# aspect here, otherwise the twin axes forces the original axes' limits (to respect
649+
# aspect=1) which makes some of the values below go out of bounds.
650+
ax.set_aspect("auto")
651+
tax = ax.twinx()
652+
646653
tool = widgets.SpanSelector(ax, onselect, orientation, **kwargs)
647654
do_event(tool, 'press', xdata=100, ydata=100, button=1)
648655
# move outside of axis
@@ -925,7 +932,7 @@ def mean(vmin, vmax):
925932

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

10341041
assert submit_event.call_count == 2
10351042

1036-
do_event(tool, '_click')
1043+
do_event(tool, '_click', xdata=.5, ydata=.5) # Ensure the click is in the axes.
10371044
do_event(tool, '_keypress', key='+')
10381045
do_event(tool, '_keypress', key='5')
10391046

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

16331640

16341641
def test_polygon_selector_box(ax):
1635-
# Create a diamond shape
1642+
# Create a diamond (adjusting axes lims s.t. the diamond lies within axes limits).
1643+
ax.set(xlim=(-10, 50), ylim=(-10, 50))
16361644
verts = [(20, 0), (0, 20), (20, 40), (40, 20)]
16371645
event_sequence = [
16381646
*polygon_place_vertex(*verts[0]),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy