Skip to content
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

FIX: don't round image sizes to pixel if meant to be unsampled #25704

Merged
merged 1 commit into from Apr 25, 2023

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Apr 17, 2023

Closes #8981

PR Summary

For images we do some pixel rounding, but if we are doing unsampled images (eg imshow(..., interpolation='none')) and saving to a backend that allows rasters (svg, pdf), then we don't want to do the pixel rounding - that just makes the image sizes fractionally too large when that isn't needed at all if we don't resample.

All the test images that changed just model my a pixel, and all have imshow(..., interpolation='none').

Old

Old

New

New

code

import numpy as np
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([0, 0, 1, 1, 0], [0, 1, 1, 0, 0], color='r', lw=0.1)
np.random.seed(19680801)
ax.imshow(np.random.randn(16, 16), cmap='Blues', extent=(0, 1, 0, 1),
            interpolation='none', vmin=-1,vmax=1)
ax.set_xlim(-0.1, 1+0.1)
ax.set_ylim(-0.1, 1+0.1)

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@jklymak jklymak marked this pull request as ready for review April 17, 2023 04:40
@jklymak jklymak added this to the v3.8.0 milestone Apr 17, 2023
Copy link
Contributor

@oscargus oscargus left a comment

Choose a reason for hiding this comment

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

I haven't checked, but maybe make sure that all of the now modified images have style='mpl20'?

@jklymak
Copy link
Member Author

jklymak commented Apr 17, 2023

I think for review send posterity it probably makes sense to leave the images in the style they are already in? It's pretty easy to see they are only trivially changed whereas if we changed the colormaps they would change a lot. I think the style changes are minimal for these ones anyway - just colormaps for instance. While I appreciate there are those who hate jet, it's probably OK for testing 😀

@oscargus
Copy link
Contributor

Yes, it for sure make sense during the review to use the same style. Was more thinking of the overall goal from #24716

@jklymak
Copy link
Member Author

jklymak commented Apr 17, 2023

Hopefully it will be moot when @tacaswell finishes his procedure for keeping track of image changes

@ksunden ksunden merged commit 139c045 into matplotlib:main Apr 25, 2023
37 of 39 checks passed
@QuLogic
Copy link
Member

QuLogic commented Jun 28, 2023

@meeseeksdev backport to v3.7.x

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jun 28, 2023
@QuLogic QuLogic modified the milestones: v3.8.0, v3.7.2 Jun 28, 2023
QuLogic added a commit that referenced this pull request Jun 29, 2023
…704-on-v3.7.x

Backport PR #25704 on branch v3.7.x (FIX: don't round image sizes to pixel if meant to be unsampled)
@jklymak jklymak deleted the fix-dont-round-unsampled branch March 22, 2024 16:13
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.

Incorrect imshow extent in PDF backend
4 participants