Skip to content

corrupt eps output on python3 #3494

Closed
Closed

Description

@japs

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

Activity

  1. added this to the v1.4.x milestone on Sep 10, 2014
  2. tacaswell commented on Sep 10, 2014

    @tacaswell
    Member

    what version of mpl are you using?

  3. tacaswell commented on Sep 10, 2014

    @tacaswell
    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.

  4. tacaswell commented on Sep 10, 2014

    @tacaswell
    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.

  5. added a commit that references this issue on Sep 10, 2014
    181ce57
  6. japs commented on Sep 10, 2014

    @japs
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions