FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Bounding box no longer works for EPS files if usetex=True · Issue #85 · matplotlib/matplotlib · GitHub

Repository navigation

Bounding box no longer works for EPS files if usetex=True #85

Closed

Description

The following code no longer sets the bounding box correctly:

import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import numpy as np

mpl.rc('text', usetex=True)

fig = plt.figure()
ax = fig.add_axes([0.1,0.1,0.3,0.3])
fig.savefig('test.eps', bbox_inches='tight')

This stopped working since commit 32f64b0, specifically the changes by @efiring.

Activity

  1. astrofrog commented on Apr 15, 2011

    ContributorAuthor

    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)
    
  2. efiring commented on Apr 17, 2011

    Member

    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.

  3. leejjoon commented on Apr 17, 2011

    Contributor

    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.

  4. astrofrog commented on Apr 17, 2011

    ContributorAuthor

    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:

    $ grep Box test_fails.eps 
    %%BoundingBox: 0 0 214 160
    %%HiResBoundingBox: 0.360000 0.312000 213.359993 159.311995
    %%PageBoundingBox: 0 0 612 792
    
    $ grep Box test_works.eps 
    %%BoundingBox: 0 0 214 160
    %%HiResBoundingBox: 0.000000 0.000000 213.636463 159.556646
    <</Type/FontDescriptor/FontName/MCSZLR+CMMI12/FontBBox[0 0 184 97]/Flags 65540
    <</Type/FontDescriptor/FontName/GCONTZ+CMR12/FontBBox[0 -21 462 675]/Flags 65568
    <</Type/Page/MediaBox [0 0 612 792]
    

    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.

  5. leejjoon commented on Apr 18, 2011

    Contributor

    Check my pull request #87 and see if it works.

  6. astrofrog commented on Apr 21, 2011

    ContributorAuthor

    @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

  7. leejjoon commented on Apr 21, 2011

    Contributor

    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)
    
  8. astrofrog commented on Apr 21, 2011

    ContributorAuthor

    With your pull request applied, the ps2write change, and the line change above, the bounding box works correctly.

  9. leejjoon commented on Apr 22, 2011

    Contributor

    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

    1. Check the version of ghostscript
    2. If greater than 9.0, use "ps2writer" and "pstoeps(tmpfile, bbox, rotated=rotated)"
    3. 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.

    -JJ

  10. added a commit that references this issue on Apr 25, 2011
    42c5dd0
  11. leejjoon commented on Apr 25, 2011

    Contributor

    @astrofrog - check #92 for ps2write issue.

  12. added a commit that references this issue on Sep 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL