Skip to content

Only change axes aspect in imshow if image transform is/contains transData #26122

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
Jul 14, 2023

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jun 14, 2023

If the image transform does not contain transData then setting the axes aspect to 1 will typically not help to make image pixel squares anyways.

Closes #14118.

PR summary

PR checklist

@@ -5585,6 +5585,11 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
that the data fit in the Axes. In general, this will result in
non-square pixels.

This parameter is ignored if the image uses a transform that does
Copy link
Member

Choose a reason for hiding this comment

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

Is this really what we want? If you do this then aspect=2 no longer will work. This seems like such an edge case, I'd rather just force users to pass aspect='auto', eg keep the current state.

or im.get_transform().contains_branch(self.transData)):
if aspect is None:
aspect = mpl.rcParams['image.aspect']
self.set_aspect(aspect)
Copy link
Member

Choose a reason for hiding this comment

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

I agree ignoring explicit user input is bad, I think we should only skip doing something with aspect if aspect is None.

Copy link
Member

Choose a reason for hiding this comment

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

I could also see a case for raising if both transform and aspect are passed...

… transData.

If the image transform does not contain transData then setting the axes
aspect to 1 will typically not help to make image pixel squares anyways.
@anntzer
Copy link
Contributor Author

anntzer commented Jul 14, 2023

Fair enough, I only changed the behavior of aspect=None (which typically means the user did not pass aspect), in which case I interpret that as meaning "don't touch the aspect" if a non-transData-derived transform is set.

@jklymak
Copy link
Member

jklymak commented Jul 14, 2023

Failing tests are an upload to codecov error. I'll merge as I feel @tacaswell and I had the same point and this fixes it.

@jklymak jklymak merged commit 3044bde into matplotlib:main Jul 14, 2023
@anntzer anntzer deleted the ai branch July 14, 2023 17:18
@QuLogic QuLogic added this to the v3.8.0 milestone Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

imshow() should not modify axes aspect if transform != ax.transData.
5 participants