You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Request an inaxes method in Figure to calculate whether a point is in an axes. #9821
Request an inaxes method in Figure to calculate whether a point is in an axes and return the axes. i.e.
def inaxes(self, xy):
axes_list = [a for a in self.get_axes() if a.patch.contains_point(xy)]
if len(axes_list) == 0:
axes = None
elif len(axes_list) > 1: # Overlap, get the highest zorder
axes_list.sort(key=lambda x: x.zorder)
axes = axes_list[-1] # Use the highest zorder
else:
axes = axes_list[0]
return axes
Rational: This make it easier (in my opinion) to find a method that do the requested method. Alternative is to create a LocationEvent and use the inaxes attribute. Using the LocationEvent class may trigger axes_enter_event and axes_leave_event.
In any cases a good documentation on matplotlib's coordinate and how to convert different backends' coordinate to matplotlib, most of the time flip the y axis, is needed.
I guess the issue here is whether xy is in screen or data coordinates -- passing in a mouse event is unambiguous. If we do decide on one convention (it is easy to switch from one to the other using the correct transform), then I'd rather fix Artist.contains to support both mouse events or xy as inputs; and promote cbook._topmost_artist to be a public API, so that you can do something like
cbook.topmost_artist([ax for ax in ... if ax.contains(xy)[0]])
On the other hand, I don't think manually instantiating a LocationEvent is that bad, especially if the point is only to use it in internal implementations (and I don't understand your comment that I'd trigger an event -- AFAICT it won't?)
LocationEvent("", fig.canvas, x, y)
In general I don't think you need to manually bother with flipy, ax.transAxes/ax.transData should (I guess?) take care of it for you.
def _update_enter_leave(self):
'process the figure/axes enter leave events'
if LocationEvent.lastevent is not None:
last = LocationEvent.lastevent
if last.inaxes != self.inaxes:
# process axes enter/leave events
try:
if last.inaxes is not None:
last.canvas.callbacks.process('axes_leave_event', last)
except:
pass
# See ticket 2901582.
# I think this is a valid exception to the rule
# against catching all exceptions; if anything goes
# wrong, we simply want to move on and process the
# current event.
if self.inaxes is not None:
self.canvas.callbacks.process('axes_enter_event', self)
else:
# process a figure enter event
if self.inaxes is not None:
self.canvas.callbacks.process('axes_enter_event', self)
This method is called when LocationEvent is instantiate.
Activity
anntzer commentedon Nov 21, 2017
I guess the issue here is whether xy is in screen or data coordinates -- passing in a mouse event is unambiguous. If we do decide on one convention (it is easy to switch from one to the other using the correct transform), then I'd rather fix Artist.contains to support both mouse events or xy as inputs; and promote cbook._topmost_artist to be a public API, so that you can do something like
On the other hand, I don't think manually instantiating a LocationEvent is that bad, especially if the point is only to use it in internal implementations (and I don't understand your comment that I'd trigger an event -- AFAICT it won't?)
In general I don't think you need to manually bother with flipy, ax.transAxes/ax.transData should (I guess?) take care of it for you.
lkjell commentedon Nov 21, 2017
This method is called when LocationEvent is instantiate.
anntzer commentedon Nov 21, 2017
ouch.
Good catch. This should probably be clearly documented too...
lkjell commentedon Nov 21, 2017
xy is the canvas coordinate, I believe is the figure.bbox. Data coordinates are the axes coordinate?
anntzer commentedon Nov 21, 2017
Axes coordinates mean 0-1, data coordinates mean xmin-xmax.
lkjell commentedon Nov 22, 2017
Need to pass in a coordinate which takes in pixel value (defaul) of the whole canvas or normalized [0,1] (keyword).
tacaswell commentedon Nov 22, 2017
@lkjell What are you doing that this came up?
lkjell commentedon Nov 22, 2017
Was working with some drag/drop to plot in qt5.
A sample script if any is interested.
QuLogic commentedon Aug 4, 2020
Appears to be fixed by #9845.