8000 Add inaxes method to FigureCanvas to check whether point is in an axes. by lkjell · Pull Request #9845 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add inaxes method to FigureCanvas to check whether point is in an axes. #9845

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

Merged
merged 6 commits into from
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move inaxes method from Figure to FigureCanvas
  • Loading branch information
lkjell committed Mar 6, 2018
commit bb5ada7f68f23d2b6ed0f35133af2d851fabe62b
6 changes: 0 additions & 6 deletions doc/users/next_whats_new/2017-11-24_figure_inaxes.rst

This file was deleted.

6 changes: 6 additions & 0 deletions doc/users/next_whats_new/2017-11-24_figurecanvas_inaxes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

Add ``inaxes`` method to FigureCanvas
-------------------------------------------------------------

The `FigureCanvas` class has now an ``inaxes`` method to check whether a point is in an axes
and returns the topmost axes, else None.
34 changes: 33 additions & 1 deletion lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ def __init__(self, name, canvas, x, y, guiEvent=None):
return

if self.canvas.mouse_grabber is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably don't want to lose the mouse-grabbing effect.

self.inaxes = self.canvas.figure.inaxes((x, y))
self.inaxes = self.canvas.inaxes((x, y))
else:
self.inaxes = self.canvas.mouse_grabber

Expand Down Expand Up @@ -1988,6 +1988,38 @@ def enter_notify_event(self, guiEvent=None, xy=None):
event = LocationEvent('figure_enter_event', self, x, y, guiEvent)
self.callbacks.process('figure_enter_event', event)

@cbook.deprecated("2.1")
def idle_event(self, guiEvent=None):
"""Called when GUI is idle."""
s = 'idle_event'
event = IdleEvent(s, self, guiEvent=guiEvent)
self.callbacks.process(s, event)

def inaxes(self, xy):
"""
Check if a point is in an axes.

Parameters
----------
xy : tuple or list
(x,y) coordinates.
x position - pixels from left of canvas.
y position - pixels from bottom of canvas.

Returns
-------
axes: topmost axes containing the point, or None if no axes.

"""
axes_list = [a for a in self.figure.get_axes() if a.patch.contains_point(xy)]

if axes_list:
axes = cbook._topmost_artist(axes_list)
else:
axes = None

return axes

def grab_mouse(self, ax):
"""
Set the child axes which are currently grabbing the mouse events.
Expand Down
25 changes: 0 additions & 25 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1532,31 +1532,6 @@ def get_axes(self):
"""
return self.axes

def inaxes(self, xy):
"""
Check if a point is in an axes.

Parameters
----------
xy : tuple or list
(x,y) coordinates.
x position - pixels from left of canvas.
y position - pixels from bottom of canvas.

Returns
-------
axes: topmost axes containing the point, or None if no axes.

"""
axes_list = [a for a in self.get_axes() if a.patch.contains_point(xy)]

if axes_list:
axes = cbook._topmost_artist(axes_list)
else:
axes = None

return axes

@docstring.dedent_interpd
def legend(self, *args, **kwargs):
"""
Expand Down
0