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

corrupt eps output on python3 #3494

Closed
japs opened this issue Sep 10, 2014 · 4 comments
Closed

corrupt eps output on python3 #3494

japs opened this issue Sep 10, 2014 · 4 comments
Milestone

Comments

@japs
Copy link

japs commented Sep 10, 2014

the following script works fine on python 2.7.8, however it produces a non valid eps file on python 3.4.1.

import numpy as np
import matplotlib
from matplotlib import pyplot as plt

if __name__ == "__main__":
    print ("Using matplotlib v%s" %matplotlib.__version__)
    x = np.linspace(0, 10)
    y = np.sin(x)

    plt.figure()
    plt.plot(x, y)
    plt.savefig("out.eps", format='eps')
    plt.show()

The two attachements following are the two outputs generated by python2 and python3 respectively (I changed the file extension to png to be able to upload them, but they are indeed eps files).
out_python2
out_python3

With a diff of the two files, and some manual editing, I found that the line responsible for the malfunctioning is the following

377c377                                                                    
< /DejaVuSans findfont                                                     
---                                                                        
> /b'DejaVuSans' findfont
@tacaswell tacaswell added this to the v1.4.x milestone Sep 10, 2014
@tacaswell
Copy link
Member

what version of mpl are you using?

@tacaswell
Copy link
Member

It looks like another str vs byte issue

The obvious source of the bug is here https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/backend_ps.py#L291 where it is trying to format a byte string into a normal string and we pick up the extra b'' (this is the same issue as the blank-screen issue fixed in #3464 ), but I suspect that what ever is calling this should be passing in a real string, not bytes.

@tacaswell
Copy link
Member

https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/backend_ps.py#L767
is the real source of the problem which explicitly turns the font name into bytes with encode, which I suspect was done to strip out non-ascii characters that eps does not support.

@japs
Copy link
Author

japs commented Sep 10, 2014

sorry, i forgot the most basic information, i'm running matplotlib 1.3.1

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

2 participants