-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: Include (0, 0) offsets in scatter autoscaling #22476
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 |
---|---|---|
|
@@ -258,9 +258,9 @@ def get_datalim(self, transData): | |
|
||
transform = self.get_transform() | ||
offset_trf = self.get_offset_transform() | ||
has_offsets = np.any(self._offsets) # True if any non-zero offsets | ||
if has_offsets and not offset_trf.contains_branch(transData): | ||
# if there are offsets but in some coords other than data, | ||
if not (isinstance(offset_trf, transforms.IdentityTransform) | ||
or offset_trf.contains_branch(transData)): | ||
# if the offsets are in some coords other than data, | ||
# then don't use them for autoscaling. | ||
return transforms.Bbox.null() | ||
offsets = self._offsets | ||
|
@@ -289,20 +289,19 @@ def get_datalim(self, transData): | |
self.get_transforms(), | ||
offset_trf.transform_non_affine(offsets), | ||
offset_trf.get_affine().frozen()) | ||
if has_offsets: | ||
# this is for collections that have their paths (shapes) | ||
# in physical, axes-relative, or figure-relative units | ||
# (i.e. like scatter). We can't uniquely set limits based on | ||
# those shapes, so we just set the limits based on their | ||
# location. | ||
|
||
offsets = (offset_trf - transData).transform(offsets) | ||
# note A-B means A B^{-1} | ||
offsets = np.ma.masked_invalid(offsets) | ||
if not offsets.mask.all(): | ||
bbox = transforms.Bbox.null() | ||
bbox.update_from_data_xy(offsets) | ||
return bbox | ||
|
||
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. Should the check for has_offsets a few lines earlier also be dropped? (if offset_trf is "anything", it certainly can map (0, 0) to anywhere and therefore autoscaling based on the collection probably doesn't make sense either. Regardless of this comment, the PR as is fixes the original issue; this is just about a more general case. 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 rid of that entire block above. |
||
# this is for collections that have their paths (shapes) | ||
# in physical, axes-relative, or figure-relative units | ||
# (i.e. like scatter). We can't uniquely set limits based on | ||
# those shapes, so we just set the limits based on their | ||
# location. | ||
offsets = (offset_trf - transData).transform(offsets) | ||
# note A-B means A B^{-1} | ||
offsets = np.ma.masked_invalid(offsets) | ||
if not offsets.mask.all(): | ||
bbox = transforms.Bbox.null() | ||
bbox.update_from_data_xy(offsets) | ||
return bbox | ||
return transforms.Bbox.null() | ||
|
||
def get_window_extent(self, renderer): | ||
|
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 am very wary of just ripping out a block of code like this without justification. The original issue was that the autoscaling logic was faulty when the offsets was basically null. But this block is for a special case where the offset transform isn't the usual transform and that we can't usually calculate the autoscale correctly in that case. Just ripping this out doesn't address this special case.
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 am also highly suspicious that ripping this block out did not trigger a test failure
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.
Thanks for the push to investigate this, Ben. You were right to be wary of this passing without any tests.
I added a new test that adds a scatter in transAxes coordinates (fixing the point in Axes space). Which I think we agree should not contribute to autoscaling. When I ripped this chunk of code out, it would have contributed.
I did however change the conditional to be: "if offsets is an updated transform (not Identity), and does not contain the transData path". Rather than checking for that possibly Falsy "has_offsets".