Skip to content

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

Merged
merged 1 commit into from
Feb 18, 2022

Conversation

greglucas
Copy link
Contributor

PR Summary

A scatter point at (0, 0) has offsets with 0s and any(offsets)
then gets evaluated to False. We still want to include this point
in the autoscaling if it is there.

Closes #22470

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).

bbox = transforms.Bbox.null()
bbox.update_from_data_xy(offsets)
return bbox

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I got rid of that entire block above.

if has_offsets and not offset_trf.contains_branch(transData):
# if there are offsets but in some coords other than data,
# then don't use them for autoscaling.
return transforms.Bbox.null()
Copy link
Member

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.

Copy link
Member

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

Copy link
Contributor Author

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".

A scatter point at (0, 0) has offsets with 0s and any(offsets)
then gets evaluated to False. We still want to include this point
in the autoscaling if it is there.
@tacaswell tacaswell added this to the v3.5.2 milestone Feb 18, 2022
@tacaswell tacaswell merged commit 91e8ea1 into matplotlib:main Feb 18, 2022
@lumberbot-app
Copy link

lumberbot-app bot commented Feb 18, 2022

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v3.5.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -m1 91e8ea112a0348fea85dad50c24859befbec3292
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #22476: FIX: Include (0, 0) offsets in scatter autoscaling'
  1. Push to a named branch:
git push YOURFORK v3.5.x:auto-backport-of-pr-22476-on-v3.5.x
  1. Create a PR against branch v3.5.x, I would have named this PR:

"Backport PR #22476 on branch v3.5.x (FIX: Include (0, 0) offsets in scatter autoscaling)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

greglucas pushed a commit to greglucas/matplotlib that referenced this pull request Feb 18, 2022
@greglucas greglucas deleted the fix-scatter-zeros branch February 18, 2022 14:44
tacaswell added a commit that referenced this pull request Feb 18, 2022
…-v3.5.x

Backport PR #22476: FIX: Include (0, 0) offsets in scatter autoscaling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Subsequent scatter plots work incorrectly
5 participants