Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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), settingthe %%BoundingBox based on that positioning. But the eps file formatdoesn't actually record the full page size (that's not the intent of theeps format anyways), just the position of the drawing relative to anorigin.GhostScript is then used to rasterize the eps images during testing; itimplicitly 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 areOK... except if the test figure is nondefault and actually *bigger* thanlettersized; in that case ghostscript will just crop out whatever is outof the lettersized paper. Note that such an image comparison test won't*fail*; it will just fail to compare anything that's outside of thelettersize 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```pythonimport subprocessfrom matplotlib.figure import Figurefor 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 notperform the centering -- but there were so few tests using eps that thedifference in behavior was entirely hidden by the general mplcairo testtolerance, until some more tests were added in matplotlib 3.6.)
anntzer commentedSep 27, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 |
anntzer commentedSep 28, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Ah, thanks for letting me know. Fixed accordingly. |
…ipt with -dEPSCrop.
…018-on-v3.6.xBackport PR#24018 on branch v3.6.x (When comparing eps images, run ghostscript with -dEPSCrop.)
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 actuallybigger 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'tfail; 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).