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

afm.py error in python3 #3473

Closed
pgnub opened this issue Sep 5, 2014 · 1 comment
Closed

afm.py error in python3 #3473

pgnub opened this issue Sep 5, 2014 · 1 comment

Comments

@pgnub
Copy link

pgnub commented Sep 5, 2014

This code raises a unexpected TypeError in Python 3.

import matplotlib.pyplot as plt

plt.rcParams['ps.useafm'] = True
plt.yscale('log')
plt.plot([1, 2, 3, 4])
plt.savefig('test.eps')

...
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/afm.py", line 101, in _sanity_check
if not line.startswith(b'StartFontMetrics'):
TypeError: startswith first arg must be str or a tuple of str, not bytes

I think that it should be solved editing the file afm.py and forcing the variable line to be of type bytes (because sometimes -I don't know why- it could be str), for instance, writing these 2 lines of code before the statements similar to: if not line.startswith(b'....Some string....') (lines 101, 155 and 198 of afm.py --- maybe also in 233, 244 and 277...)

if isinstance(line, str):
    line = line.encode()
@tacaswell tacaswell added this to the v1.4.x milestone Sep 5, 2014
@tacaswell tacaswell added the text label Sep 5, 2014
@pgnub
Copy link
Author

pgnub commented Sep 6, 2014

Maybe this is a better solution:
file mathtext.py, line 1037: Open file in mode rb instead of r, so:
1037: with open(filename, 'rb') as fd:
Greetings

@tacaswell tacaswell modified the milestones: 1.5.0, v1.4.x Feb 7, 2015
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Jul 17, 2015
Followed suggestion of @pgnub

Closes matplotlib#3473

Adds test coverage for afm handling
@tacaswell tacaswell self-assigned this Jul 17, 2015
@QuLogic QuLogic added Py3k compat and removed Py3k labels Feb 18, 2018
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

3 participants