Skip to content

Multicursor updates to events for any axis #19635

Closed

Description

@ianhi

Bug report

Bug summary
The multicursor widget does not check if the events it receives are in the axes it received in init. So mouse move events on any axis in the figure will cause the cursor to move.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import MultiCursor

t = np.arange(0.0, 2.0, 0.01)
s1 = np.sin(2*np.pi*t)
s2 = np.sin(4*np.pi*t)

fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True)
ax1.plot(t, s1)
ax2.plot(t, s2)

multi = MultiCursor(fig.canvas, (ax1, ax2), color='r', lw=1, useblit=False)
plt.show()

Actual outcome
Peek 2021-03-03 18-59

Expected outcome
Mouse moving in the bottom subplot does not affect the cursor position.

Matplotlib version

  • Operating system: Ubuntu
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): master
  • Matplotlib backend (print(matplotlib.get_backend())): any
  • Python version: 3.9.1

Activity

  1. ianhi commented on Mar 4, 2021

    @ianhi
    ContributorAuthor

    The fix here is to change:

    def onmove(self, event):
    if self.ignore(event):
    return
    if event.inaxes is None:
    return

    to have the second if statement read:

         if not event.inaxes in self.axes: 
             return 
    
  2. ianhi commented on Mar 4, 2021

    @ianhi
    ContributorAuthor

    I guess it's actually a little bit unclear what the intended behavior is. I could see an argument that the reason you are providing the axes is just to denote which axes get a line drawn on them, but without a docstring (#19634) it's hard to say. Though my expectation is definitely that the only axes that should matter are the ones that get passed to init.

  3. added this to the v3.5.0 milestone on Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions