Adding back the following code in backend_ps.py resolves this issue, but maybe it was removed for a good reason?
# While it is best if above steps preserve the original bounding
# box, it does not seems to be the case. pstoeps not only convert
# the input to eps format, but also restores the original bbox.
if eps:
pstoeps(tmpfile, bbox, rotated=rotated)
It was removed to resolve 3032385, which it did on JJ's system and on mine.
Please be more specific: is the bbox error subtle or large? I see small but significant differences among bounding boxes with various combinations of text and distillation, but I don't see a large error.
bbox issue in the ps backend is tricky to handle. And often the behavior depends on the ghostscript (or xpdf) version.
So please report your distiller setting with following information.
version of ghostscript
version of pdftops if you use xpdf distiller.
I then ran this with the latest matplotlib from git, and the bounding box is wrong in the sense that it seems to be set to a whole page rather than just the axes (@efiring - the error is definitely very large). I then added the code I mentioned above to backend_ps.py and the bounding box is then set correctly. I have uploaded the EPS files to https://www.dropbox.com/s/qyi6kkul378w7md for you to see - test_fails.eps is what I get with the latest matplotlib version, while test_works.eps is what I get when I add the pstoeps() call in backend_ps.py. Grepping for Box in the two files shows that the file that works has extra bounding box commands:
The exact commit I'm working on in matplotlib is 08ac8f0 and I am using Ghostscript 9.02. Let me know if you require any additional information to track down what's going on!
@leejjoon - for another bug you had suggested I change pswrite to ps2write in lib/matplotlib/backends/backend_ps.py but this doesn't seem to change anything for the present bug.
@leejjoon - the patch works on a clean install of matplotlib, in that the bounding box is now set correctly for the example above. There is an issue which is that the fix for the image rasterization, i.e. changing pswrite to ps2write in backend_ps.py, causes this patch not to work. Here are some example files: https://www.dropbox.com/s/294kxuvfw0efmm6
I don't seem to reproduce the bug with gs 9.0.1. I'll check with 9.0.2 soon.
Meanwhile, please try this and let me know what happens.
With my pull request applied (and w/ ps2write), comment out line 1399 of backend_ps.py. Instead, uncomment line 1394.
i.e., it should look like this
if eps:
pstoeps(tmpfile, bbox, rotated=rotated)
# For some versions of gs, above steps result in an ps file
# where the original bbox is no more correct. Do not adjust
# bbox for now.
# pstoeps(tmpfile)
It seems that with gs 9.0 and later, we'd better go with ps2write (http://www.cups.org/str.php?L3766).
Therefore, I think what we need is
Check the version of ghostscript
If greater than 9.0, use "ps2writer" and "pstoeps(tmpfile, bbox, rotated=rotated)"
Otherwise, use "pswriter" and "pstoeps(tmpfile)"
It is possible that the situation is more complicated, but let's see how it works.
I'll try to work on it soon (any contribution will be appreciated).
I'll push my original change (the pull request) into the maintenance branch and will close this issue.
And then I'll open another issue with the ps2writer thing.
Activity
astrofrog commented on Apr 15, 2011
Adding back the following code in backend_ps.py resolves this issue, but maybe it was removed for a good reason?
# While it is best if above steps preserve the original bounding # box, it does not seems to be the case. pstoeps not only convert # the input to eps format, but also restores the original bbox. if eps: pstoeps(tmpfile, bbox, rotated=rotated)efiring commented on Apr 17, 2011
It was removed to resolve 3032385, which it did on JJ's system and on mine.
Please be more specific: is the bbox error subtle or large? I see small but significant differences among bounding boxes with various combinations of text and distillation, but I don't see a large error.
leejjoon commented on Apr 17, 2011
bbox issue in the ps backend is tricky to handle. And often the behavior depends on the ghostscript (or xpdf) version.
So please report your distiller setting with following information.
version of ghostscript
version of pdftops if you use xpdf distiller.
astrofrog commented on Apr 17, 2011
Since I wasn't sure which distiller was being used, I forced it to 'ghostscript':
import matplotlib as mpl mpl.use('Agg') import matplotlib.pyplot as plt mpl.rc('text', usetex=True) mpl.rc('ps', usedistiller='ghostscript') fig = plt.figure() ax = fig.add_axes([0.1,0.1,0.3,0.3]) fig.savefig('test.eps', bbox_inches='tight')I then ran this with the latest matplotlib from git, and the bounding box is wrong in the sense that it seems to be set to a whole page rather than just the axes (@efiring - the error is definitely very large). I then added the code I mentioned above to backend_ps.py and the bounding box is then set correctly. I have uploaded the EPS files to https://www.dropbox.com/s/qyi6kkul378w7md for you to see - test_fails.eps is what I get with the latest matplotlib version, while test_works.eps is what I get when I add the pstoeps() call in backend_ps.py. Grepping for Box in the two files shows that the file that works has extra bounding box commands:
The exact commit I'm working on in matplotlib is 08ac8f0 and I am using Ghostscript 9.02. Let me know if you require any additional information to track down what's going on!
@leejjoon - for another bug you had suggested I change pswrite to ps2write in lib/matplotlib/backends/backend_ps.py but this doesn't seem to change anything for the present bug.
leejjoon commented on Apr 18, 2011
Check my pull request #87 and see if it works.
astrofrog commented on Apr 21, 2011
@leejjoon - the patch works on a clean install of matplotlib, in that the bounding box is now set correctly for the example above. There is an issue which is that the fix for the image rasterization, i.e. changing pswrite to ps2write in backend_ps.py, causes this patch not to work. Here are some example files: https://www.dropbox.com/s/294kxuvfw0efmm6
leejjoon commented on Apr 21, 2011
I don't seem to reproduce the bug with gs 9.0.1. I'll check with 9.0.2 soon.
Meanwhile, please try this and let me know what happens.
With my pull request applied (and w/ ps2write), comment out line 1399 of backend_ps.py. Instead, uncomment line 1394.
i.e., it should look like this
if eps: pstoeps(tmpfile, bbox, rotated=rotated) # For some versions of gs, above steps result in an ps file # where the original bbox is no more correct. Do not adjust # bbox for now. # pstoeps(tmpfile)astrofrog commented on Apr 21, 2011
With your pull request applied, the ps2write change, and the line change above, the bounding box works correctly.
leejjoon commented on Apr 22, 2011
Okay, glad to hear that worked.
It seems that with gs 9.0 and later, we'd better go with ps2write (http://www.cups.org/str.php?L3766).
Therefore, I think what we need is
It is possible that the situation is more complicated, but let's see how it works.
I'll try to work on it soon (any contribution will be appreciated).
I'll push my original change (the pull request) into the maintenance branch and will close this issue.
And then I'll open another issue with the ps2writer thing.
-JJ
gs distiller uses pstoeps but do not replace bbox. closes matplotlib#85.
leejjoon commented on Apr 25, 2011
@astrofrog - check #92 for ps2write issue.
Merge pull request matplotlib#85 from fgoudreault/camera_environment_…