Commit d1f3a0d
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
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| |||
0 commit comments