Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
QuLogic merged 2 commits intomatplotlib:mainfromanntzer:depscrop
Sep 28, 2022

Conversation

anntzer
Copy link
Contributor

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

importsubprocessfrommatplotlib.figureimportFigureforfsin [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.)

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

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

Documentation

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

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
Copy link
ContributorAuthor

anntzer commentedSep 27, 2022
edited
Loading

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.

@QuLogic
Copy link
Member

The1- is there for bumping when necessary.

@anntzer
Copy link
ContributorAuthor

anntzer commentedSep 28, 2022
edited
Loading

Ah, thanks for letting me know. Fixed accordingly.

@QuLogicQuLogic merged commit6fb17d9 intomatplotlib:mainSep 28, 2022
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestSep 28, 2022
QuLogic added a commit that referenced this pull requestSep 29, 2022
…018-on-v3.6.xBackport PR#24018 on branch v3.6.x (When comparing eps images, run ghostscript with -dEPSCrop.)
@anntzeranntzer deleted the depscrop branchSeptember 29, 2022 05:43
@ksundenksunden mentioned this pull requestFeb 20, 2023
6 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic approved these changes

@oscargusoscargusoscargus approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.6.1
Development

Successfully merging this pull request may close these issues.

3 participants
@anntzer@QuLogic@oscargus

[8]ページ先頭

©2009-2025 Movatter.jp