Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Include child Axes inaxes calculation#25050

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
QuLogic wants to merge1 commit intomatplotlib:mainfromQuLogic:inaxes-children

Conversation

QuLogic
Copy link
Member

PR Summary

This makesInsetAxes count for this field, and allows widgets to work in them.

Now, one question is thatinaxes now is the innermost Axes only. That meansaxes_leave_event is triggered for a parentAxes when entering the child. Is that the behaviour that's desired? If we instead want this to only trigger whencompletely outside the parentAxes, we'd have to do something like makeinaxes a list (or a private-but-related field if we don't want to change API.)

Fixes#25030

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (andpytest passes)
  • [n/a] Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • [n/a] New plotting related features are documented with examples.

Release Notes

  • [n/a] New features are marked with a.. versionadded:: directive in the docstring and documented indoc/users/next_whats_new/
  • [n/a] API changes are marked with a.. versionchanged:: directive in the docstring and documented indoc/api/next_api_changes/
  • [n/a] Release notes conform with instructions innext_whats_new/README.rst ornext_api_changes/README.rst

This makes InsetAxes count for this field, and allows widgets to work inthem.Fixesmatplotlib#25030
@QuLogic
Copy link
MemberAuthor

As an example, I took the code fromevent_handling.rst, and modified it to use nestedInsetAxes:

"""Illustrate the figure and axes enter and leave events by changing theframe colors on enter and leave"""importmatplotlib.pyplotaspltdefenter_axes(event):print('enter_axes',event.inaxes)event.inaxes.patch.set_facecolor('yellow')event.canvas.draw()defleave_axes(event):print('leave_axes',event.inaxes)event.inaxes.patch.set_facecolor('white')event.canvas.draw()defenter_figure(event):print('enter_figure',event.canvas.figure)event.canvas.figure.patch.set_facecolor('red')event.canvas.draw()defleave_figure(event):print('leave_figure',event.canvas.figure)event.canvas.figure.patch.set_facecolor('grey')event.canvas.draw()fig,ax=plt.subplots()fig.suptitle('mouse hover over figure or axes to trigger events')ax.set_label('Level 0')foriinrange(4):ax=ax.inset_axes([0.2,0.2,0.6,0.6])ax.set_label(f'Level{i+1}')fig.canvas.mpl_connect('figure_enter_event',enter_figure)fig.canvas.mpl_connect('figure_leave_event',leave_figure)fig.canvas.mpl_connect('axes_enter_event',enter_axes)fig.canvas.mpl_connect('axes_leave_event',leave_axes)plt.show()

If you mouse over, then you will see the outerAxes leave events trigger as the mouse enters the innerAxes (i.e., only oneAxes will ever be yellow).

@jklymak
Copy link
Member

It wouldn't seem that you want to say you left the axes if you didn't leave the axes? I'm a little unclear of the use case here - do we want inset axes to have widgets in them? Not clear what the interactive logic is here, particularly as an inset axes doesn'thave to be on top of the parent at all. Is there a reason we only check if the mouse is in an axes versus over a GUI element?

@anntzer
Copy link
Contributor

In general I think axes_enter_event/axes_leave_event are rather poorly specified, exactly because it's unclear what should happen with overlapping axes.
Also the patch here is likely wrong, as noted by@jklymak, if the inset axes is not actually within the parent; this is actually a use case demonstrated inhttps://matplotlib.org/stable/gallery/lines_bars_and_markers/scatter_hist.html

FWIW I would just get rid of axes_enter_event and axes_leave_event, and just hook to motion_notify_event, something like

frommatplotlibimportpyplotaspltdefon_motion(event):inaxes=event.inaxes# Depends on the actual inaxes semantics, of course.foraxinaxs:ax.patch.set_facecolor("w")ifinaxes:inaxes.patch.set_facecolor("y")event.canvas.draw()# Could draw only if a change was actually made.axs= []fig,ax=plt.subplots()ax.set_label('Level 0')axs.append(ax)foriinrange(4):ax=ax.inset_axes([0.2,0.2,0.6,0.6])ax.set_label(f'Level{i+1}')axs.append(ax)fig.canvas.mpl_connect('motion_notify_event',on_motion)plt.show()

@anntzer
Copy link
Contributor

anntzer commentedMay 12, 2023
edited
Loading

I think#25555 may be a more general fix for the original issue, although it does not try to address what axes_{enter,leave}_event means in the presence of overlapping axes (again, I think that was not a really well-defined API to start with...).

@QuLogic
Copy link
MemberAuthor

Yes, I thought that might be the case when I first saw that PR, but did not try it out.

@QuLogic
Copy link
MemberAuthor

The original issuewas fixed by#25555. While we should work out semantics foraxes_enter/leave_event, not sure this is the right way to that.

@QuLogicQuLogic closed thisAug 1, 2023
@QuLogicQuLogic deleted the inaxes-children branchDecember 8, 2023 03:05
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[BUG]: Button widgets don't work in inset axes
3 participants
@QuLogic@jklymak@anntzer

[8]ページ先頭

©2009-2025 Movatter.jp