Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe65fdc

Browse files
authored
Merge pull request #20232 from meeseeksmachine/auto-backport-of-pr-19636-on-v3.4.x
Backport PR #19636 on branch v3.4.x (Correctly check inaxes for multicursor)
2 parents c315e45 + c5e3ac5 commit fe65fdc

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

lib/matplotlib/tests/test_widgets.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import matplotlib.widgets as widgets
33
import matplotlib.pyplot as plt
44
from matplotlib.testing.decorators import image_comparison
5-
from matplotlib.testing.widgets import do_event, get_ax
5+
from matplotlib.testing.widgets import do_event, get_ax, mock_event
66

77
from numpy.testing import assert_allclose
88

@@ -464,3 +464,43 @@ def test_polygon_selector():
464464
+ polygon_place_vertex(50, 150)
465465
+ polygon_place_vertex(50, 50))
466466
check_polygon_selector(event_sequence, expected_result, 1)
467+
468+
469+
@pytest.mark.parametrize(
470+
"horizOn, vertOn",
471+
[(True, True), (True, False), (False, True)],
472+
)
473+
def test_MultiCursor(horizOn, vertOn):
474+
fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True)
475+
476+
# useblit=false to avoid having to draw the figure to cache the renderer
477+
multi = widgets.MultiCursor(
478+
fig.canvas, (ax1, ax2), useblit=False, horizOn=horizOn, vertOn=vertOn
479+
)
480+
481+
# Only two of the axes should have a line drawn on them.
482+
if vertOn:
483+
assert len(multi.vlines) == 2
484+
if horizOn:
485+
assert len(multi.hlines) == 2
486+
487+
# mock a motion_notify_event
488+
# Can't use `do_event` as that helper requires the widget
489+
# to have a single .ax attribute.
490+
event = mock_event(ax1, xdata=.5, ydata=.25)
491+
multi.onmove(event)
492+
493+
# the lines in the first two ax should both move
494+
for l in multi.vlines:
495+
assert l.get_xdata() == (.5, .5)
496+
for l in multi.hlines:
497+
assert l.get_ydata() == (.25, .25)
498+
499+
# test a move event in an axes not part of the MultiCursor
500+
# the lines in ax1 and ax2 should not have moved.
501+
event = mock_event(ax3, xdata=.75, ydata=.75)
502+
multi.onmove(event)
503+
for l in multi.vlines:
504+
assert l.get_xdata() == (.5, .5)
505+
for l in multi.hlines:
506+
assert l.get_ydata() == (.25, .25)

lib/matplotlib/widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ def clear(self, event):
16551655
def onmove(self, event):
16561656
if self.ignore(event):
16571657
return
1658-
if event.inaxes is None:
1658+
if event.inaxes not in self.axes:
16591659
return
16601660
if not self.canvas.widgetlock.available(self):
16611661
return

0 commit comments

Comments
 (0)