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

Skip to content

Commit bb5ada7

Browse files
committed
Move inaxes method from Figure to FigureCanvas
1 parent 1628e7c commit bb5ada7

File tree

4 files changed

+39
-32
lines changed

4 files changed

+39
-32
lines changed

doc/users/next_whats_new/2017-11-24_figure_inaxes.rst

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
Add ``inaxes`` method to FigureCanvas
3+
-------------------------------------------------------------
4+
5+
The `FigureCanvas` class has now an ``inaxes`` method to check whether a point is in an axes
6+
and returns the topmost axes, else None.

lib/matplotlib/backend_bases.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ def __init__(self, name, canvas, x, y, guiEvent=None):
14971497
return
14981498

14991499
if self.canvas.mouse_grabber is None:
1500-
self.inaxes = self.canvas.figure.inaxes((x, y))
1500+
self.inaxes = self.canvas.inaxes((x, y))
15011501
else:
15021502
self.inaxes = self.canvas.mouse_grabber
15031503

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

1991+
@cbook.deprecated("2.1")
1992+
def idle_event(self, guiEvent=None):
1993+
"""Called when GUI is idle."""
1994+
s = 'idle_event'
1995+
event = IdleEvent(s, self, guiEvent=guiEvent)
1996+
self.callbacks.process(s, event)
1997+
1998+
def inaxes(self, xy):
1999+
"""
2000+
Check if a point is in an axes.
2001+
2002+
Parameters
2003+
----------
2004+
xy : tuple or list
2005+
(x,y) coordinates.
2006+
x position - pixels from left of canvas.
2007+
y position - pixels from bottom of canvas.
2008+
2009+
Returns
2010+
-------
2011+
axes: topmost axes containing the point, or None if no axes.
2012+
2013+
"""
2014+
axes_list = [a for a in self.figure.get_axes() if a.patch.contains_point(xy)]
2015+
2016+
if axes_list:
2017+
axes = cbook._topmost_artist(axes_list)
2018+
else:
2019+
axes = None
2020+
2021+
return axes
2022+
19912023
def grab_mouse(self, ax):
19922024
"""
19932025
Set the child axes which are currently grabbing the mouse events.

lib/matplotlib/figure.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,31 +1532,6 @@ def get_axes(self):
15321532
"""
15331533
return self.axes
15341534

1535-
def inaxes(self, xy):
1536-
"""
1537-
Check if a point is in an axes.
1538-
1539-
Parameters
1540-
----------
1541-
xy : tuple or list
1542-
(x,y) coordinates.
1543-
x position - pixels from left of canvas.
1544-
y position - pixels from bottom of canvas.
1545-
1546-
Returns
1547-
-------
1548-
axes: topmost axes containing the point, or None if no axes.
1549-
1550-
"""
1551-
axes_list = [a for a in self.get_axes() if a.patch.contains_point(xy)]
1552-
1553-
if axes_list:
1554-
axes = cbook._topmost_artist(axes_list)
1555-
else:
1556-
axes = None
1557-
1558-
return axes
1559-
15601535
@docstring.dedent_interpd
15611536
def legend(self, *args, **kwargs):
15621537
"""

0 commit comments

Comments
 (0)