Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1f3a0d

Browse files
committed
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 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.)
1 parent 0c5b792 commit d1f3a0d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/matplotlib/testing/compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def __call__(self, orig, dest):
103103
if not self._proc:
104104
self._proc = subprocess.Popen(
105105
[mpl._get_executable_info("gs").executable,
106-
"-dNOSAFER", "-dNOPAUSE", "-sDEVICE=png16m"],
106+
"-dNOSAFER", "-dNOPAUSE", "-dEPSCrop", "-sDEVICE=png16m"],
107107
# As far as I can see, ghostscript never outputs to stderr.
108108
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
109109
try:

0 commit comments

Comments
 (0)