-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
When comparing eps images, run ghostscript with -dEPSCrop. #24018
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Currently, the ps backend positions eps images into an imaginary page (the smallest standard page size which can contain the figure size, which happens to be lettersized for the default figure size), setting the %%BoundingBox based on that positioning. But the eps file format doesn't actually record the full page size (that's not the intent of the eps format anyways), just the position of the drawing relative to an origin. GhostScript is then used to rasterize the eps images during testing; it implicitly assumes a default page size of "letter" (https://ghostscript.readthedocs.io/en/latest/Use.html#choosing-paper-size) which just happens to match the page size selected above. So things are OK... except if the test figure is nondefault and actually *bigger* than lettersized; in that case ghostscript will just crop out whatever is out of the lettersized paper. Note that such an image comparison test won't *fail*; it will just fail to compare anything that's outside of the lettersize paper. Instead, pass -dEPSCrop to GhostScript (https://ghostscript.readthedocs.io/en/latest/Use.html#depscrop) which readjusts the papersize to match the eps bounding box. Test e.g. with ```python import subprocess from matplotlib.figure import Figure for fs in [5, 10, 15, 20]: Figure(figsize=(fs, fs)).add_subplot().figure.savefig(f"test-{fs}.eps") subprocess.run([ "gs", "-dNOSAFER", "-dNOPAUSE", "-dEPSCrop", "-o", f"test-{fs}.png", "-sDEVICE=png16m", f"test-{fs}.eps"]) ``` (Noted while troubleshooting failed tests on mplcairo, which does not perform the centering -- but there were so few tests using eps that the difference in behavior was entirely hidden by the general mplcairo test tolerance, until some more tests were added in matplotlib 3.6.)
oscargus
approved these changes
Sep 27, 2022
I think CI failed because the test conversion cache should be invalidated -- added a commit that drops the caches to check that. -- Edit: that fixed it indeed; we need to decide how to handle that cache problem. |
The |
Ah, thanks for letting me know. Fixed accordingly. |
QuLogic
approved these changes
Sep 28, 2022
meeseeksmachine
pushed a commit
to meeseeksmachine/matplotlib
that referenced
this pull request
Sep 28, 2022
…ipt with -dEPSCrop.
QuLogic
added a commit
that referenced
this pull request
Sep 29, 2022
…018-on-v3.6.x Backport PR #24018 on branch v3.6.x (When comparing eps images, run ghostscript with -dEPSCrop.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the ps backend positions eps images into an imaginary page (the smallest standard page size which can contain the figure size, which happens to be lettersized for the default figure size), setting the %%BoundingBox based on that positioning. But the eps file format doesn't actually record the full page size (that's not the intent of the eps format anyways), just the position of the drawing relative to an origin.
GhostScript is then used to rasterize the eps images during testing; it implicitly assumes a default page size of "letter" (https://ghostscript.readthedocs.io/en/latest/Use.html#choosing-paper-size) which just happens to match the page size selected above. So things are OK... except if the test figure is nondefault and actually bigger than lettersized; in that case ghostscript will just crop out whatever is out of the lettersized paper. Note that such an image comparison test won't fail; it will just fail to compare anything that's outside of the lettersize paper.
Instead, pass -dEPSCrop to GhostScript
(https://ghostscript.readthedocs.io/en/latest/Use.html#depscrop) which readjusts the papersize to match the eps bounding box.
Test e.g. with
(Noted while troubleshooting failed tests on mplcairo, which does not perform the centering -- but there were so few tests using eps that the difference in behavior was entirely hidden by the general mplcairo test tolerance, until some more tests were added in matplotlib 3.6.)
Not really a regression, but would still be nice to have this in 3.6.1 to make testing of mplcairo simpler (otherwise I'll just xfail some more tests in mplcairo...).
PR Summary
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).