8000 afm.py error in python3 · Issue #3473 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
afm.py error in python3 #3473
Closed
Closed
@pgnub

Description

@pgnub

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0