-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix data cursor for images with additional transform #18737
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -661,7 +661,8 @@ def contains(self, mouseevent): | |
# collection on nonlinear transformed coordinates. | ||
# TODO: consider returning image coordinates (shouldn't | ||
# be too difficult given that the image is rectilinear | ||
x, y = mouseevent.xdata, mouseevent.ydata | ||
trans = self.get_transform().inverted() | ||
x, y = trans.transform([mouseevent.x, mouseevent.y]) | ||
xmin, xmax, ymin, ymax = self.get_extent() | ||
if xmin > xmax: | ||
xmin, xmax = xmax, xmin | ||
|
@@ -983,13 +984,14 @@ def get_cursor_data(self, event): | |
if self.origin == 'upper': | ||
ymin, ymax = ymax, ymin | ||
arr = self.get_array() | ||
data_extent = Bbox([[ymin, xmin], [ymax, xmax]]) | ||
array_extent = Bbox([[0, 0], arr.shape[:2]]) | ||
trans = BboxTransform(boxin=data_extent, boxout=array_extent) | ||
point = trans.transform([event.ydata, event.xdata]) | ||
data_extent = Bbox([[xmin, ymin], [xmax, ymax]]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused - was the previous version just a huge bug? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you referring to the switched There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got it - I didn't trace it all through so was confused... |
||
array_extent = Bbox([[0, 0], [arr.shape[1], arr.shape[0]]]) | ||
trans = self.get_transform().inverted() | ||
trans += BboxTransform(boxin=data_extent, boxout=array_extent) | ||
point = trans.transform([event.x, event.y]) | ||
if any(np.isnan(point)): | ||
return None | ||
i, j = point.astype(int) | ||
j, i = point.astype(int) | ||
# Clip the coordinates at array bounds | ||
if not (0 <= i < arr.shape[0]) or not (0 <= j < arr.shape[1]): | ||
return None | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you aren't using
xdata
/ydata
any more, does that mean the comment about aboutfigimage
is fixed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it should be fine to remove the
self.axes is not mouseevent.inaxes
check now andcontains()
should also work for FigureImage. However, FigureImage doesn't have aget_cursor_data()
yet, so I think the only place wherecontains
would be used for a FigureImage is for the pick events? I'm not sure about that though, maybe @anntzer can help since he wrote the original comment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's likely that this fixes some of the problems I had noticed when I put in the comment, but I haven't reviewed this carefully enough to see whether all problems are indeed fixed.