Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matplotlib 1.3.1 for Python 3.2.5 on Mac OS X produces corrupt .eps files #2748

Closed
adamfreese opened this issue Jan 21, 2014 · 5 comments
Closed

Comments

@adamfreese
Copy link

This is a problem if I have usetex=True. A simple script that produces the error is

import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt
mpl.rc('text', usetex=True)
x = np.linspace(0.,5.,100)
y = np.exp(-x)
plt.plot(x,y,'k',linewidth=2)
plt.savefig("plot.eps",bbox_inches=0)

Preview cannot open plot.eps (it fails to convert it to pdf). On Arch Linux (for which I have matplotlib 1.3.1 on Python 3.3.3), the example script does not produce a corrupt file, and the difference appears to be in a few lines at the end of the file. plot.eps produced on the Mac has the lines

%%PageTrailer
%%Trailer
cleartomark
countdictstack
exch sub { end } repeat
restore
end
%%EOF

whereas the Linux plot.eps has instead

%%PageTrailer
%%Trailer
cleartomark
end
countdictstack
exch sub { end } repeat
restore
%%EOF

If I manually edit plot.eps using nano on the Mac and move the line with the word 'end' to where it is in the Linux file, then plot.eps opens in Preview and the problem disappears.

@efiring
Copy link
Member

efiring commented Jan 22, 2014

On 2014/01/21 11:00 AM, maxwellsdemon137 wrote:

This is a problem if I have usetex=True. A simple script that produces
the error is

|import numpy as np
import matplotlib as mpl

What happens on the Mac if you insert the following here?

mpl.use('ps')

from matplotlib import pyplot as plt
mpl.rc('text', usetex=True)
x = np.linspace(0.,5.,100)
y = np.exp(-x)
plt.plot(x,y,'k',linewidth=2)
plt.savefig("plot.eps",bbox_inches=0)
|

Preview cannot open plot.eps (it fails to convert it to pdf). On Arch
Linux (for which I have matplotlib 1.3.1 on Python 3.3.3), the example
script does not produce a corrupt file, and the difference appears to be
in a few lines at the end of the file. plot.eps produced on the Mac has
the lines

|%%PageTrailer
%%Trailer
cleartomark
countdictstack
exch sub { end } repeat
restore
end
%%EOF
|

whereas the Linux plot.eps has instead

|%%PageTrailer
%%Trailer
cleartomark
end
countdictstack
exch sub { end } repeat
restore
%%EOF
|

If I manually edit plot.eps using nano on the Mac and move the line with
the word 'end' to where it is in the Linux file, then plot.eps opens in
Preview and the problem disappears.


Reply to this email directly or view it on GitHub
#2748.

@adamfreese
Copy link
Author

I'm afraid I still get the same error.

@efiring
Copy link
Member

efiring commented Jan 23, 2014

@maxwellsdemon137 OK, that's what I expected, I just wanted to be sure. I think that with usetex=True the trailer is being written by ghostscript, so the problem on the Mac would be with the version of ghostscript on the Mac.

@tacaswell
Copy link
Member

Closing as this is seems to be an issue with ghostscript, not with mpl. @efiring Please reopen if I misunderstood.

@igormq
Copy link

igormq commented Oct 27, 2015

I have the same issue here, but I'm not using usetex=True.

fig = plt.figure()
plt.plot(bins[0:-1], Fk, marker='x')
plt.yscale('log')
plt.xscale('log')
fig.set_tight_layout(True)

Can you help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants