def _(artist, event):
if type(artist) != AxesImage:
# Skip and warn on subclasses (`NonUniformImage`, `PcolorImage`) as
# they do not implement `contains` correctly. Even if they did, they
# would not support moving as we do not know where a given index maps
# back physically.
return compute_pick.dispatch(object)(artist, event)
contains, _ = artist.contains(event)
if not contains:
return
ns = np.asarray(artist.get_array().shape)[::-1] # (y, x) -> (x, y)
xy = np.array([event.xdata, event.ydata])
xmin, xmax, ymin, ymax = artist.get_extent()
# Handling of "upper" origin copied from AxesImage.get_cursor_data.
if artist.origin == "upper":
ymin, ymax = ymax, ymin
low, high = np.array([[xmin, ymin], [xmax, ymax]])
idxs = ((xy - low) / (high - low) * ns).astype(int)[::-1]
target = with_attrs(xy, index=tuple(idxs))
return Selection(artist, target, 0, None, None)
评论列表
文章目录