The Wayback Machine - https://web.archive.org/web/20230512170603/https://github.com/matplotlib/matplotlib/issues/25860
Skip to content
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

[Bug]: canvas pick events not working when Axes belongs to a subfigure #25860

Open
ndeadly opened this issue May 11, 2023 · 3 comments
Open

[Bug]: canvas pick events not working when Axes belongs to a subfigure #25860

ndeadly opened this issue May 11, 2023 · 3 comments
Labels
Difficulty: Medium Good first issue Open a pull request against these issues if there are no active ones! status: confirmed bug
Milestone

Comments

@ndeadly
Copy link

ndeadly commented May 11, 2023

Bug summary

When an axis is added to a subfigure, rather than the root figure, canvas pick events are no longer received for that axis.

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib.gridspec as mgridspec
import numpy as np

def on_pick(evt):
    print('pick event!')

fig = plt.figure()
gs = mgridspec.GridSpec(1, 1)

# Pick events working
#ax = fig.add_subplot(gs[0, 0])

# Pick events not working
subfig = fig.add_subfigure(gs[0, 0])
ax = subfig.add_subplot(1, 1, 1)

ax.plot(np.random.random(10), np.random.random(10), marker='.', linestyle='none', picker=5)

fig.canvas.mpl_connect('pick_event', on_pick)
plt.show()

Actual outcome

No output.

Expected outcome

The following should be displayed on the console when one of the markers is clicked.

>> pick event!

Additional information

No response

Operating system

Windows 10

Matplotlib Version

3.7.1

Matplotlib Backend

Qt5Agg

Python version

3.8.10

Jupyter version

No response

Installation

pip

@tacaswell tacaswell added this to the v3.7.2 milestone May 11, 2023
@tacaswell tacaswell added status: confirmed bug Good first issue Open a pull request against these issues if there are no active ones! Difficulty: Medium labels May 11, 2023
@tacaswell
Copy link
Member

Thank you for the very clear report @ndeadly ! I can confirm that this is a bug.

My suspicion is that in the pick function from Figure (which might be inherited from Artist) it is not correctly offering pick events to the SubFigures of the Figure.

Tasks:

  • trace through the code for pick events in Figure and verify or disprove my theory
  • if my theory is right, offer the event to all of the SubFigures
  • [bonus] add a test. We have some machinery for creating synthetic mouse events. Either make that work or show it will me order of magnitude more code to write a test harness than the fix was.

Labeling as good first issue because it is a clear bug and there is no API design here (the pick event should fire!), but medium as it will require walking through the event handling stack and reasoning through some OO code.

@QuLogic
Copy link
Member

QuLogic commented May 12, 2023

Small note; this is about Axes, not Axis.

@QuLogic QuLogic changed the title [Bug]: canvas pick events not working when axis belongs to a subfigure [Bug]: canvas pick events not working when Axes belongs to a subfigure May 12, 2023
@QuLogic
Copy link
Member

QuLogic commented May 12, 2023

My suspicion is that in the pick function from Figure (which might be inherited from Artist) it is not correctly offering pick events to the SubFigures of the Figure.

I think this is correct, but maybe not for an expected reason; Figure inherits from Artist, which loops through self.get_children() and offers the event to children whose .axes attribute matches the event's Axes or any child if either is None. And SubFigure, like Figure, does not have a parent Axes, but it does have an axes attribute which is a list of Axes children. So this never matches the event Axes or None, and SubFigures never get picked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium Good first issue Open a pull request against these issues if there are no active ones! status: confirmed bug
Projects
None yet
Development

No branches or pull requests

3 participants