Closed
Description
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()