tikzplotlib icon indicating copy to clipboard operation
tikzplotlib copied to clipboard

save with standalone result in UniCodeEncodeError

Open Aikhjarto opened this issue 5 years ago • 0 comments
trafficstars

Calling tikzplotlib.save('test.tex',standlone=True) result in UniCodeEncodeError raised.

import tikzplotlib
tikzplotlib.save('test.tex', standalone=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "...\lib\site-packages\tikzplotlib\_save.py", line 255, in save
    file_handle.write(code)
  File "...\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2212' in position 111: character maps to <undefined>

The reason is, that the default-preamble contains a unicode dash '\u2212' but codec.open called in https://github.com/nschloe/tikzplotlib/blob/adcf150493404b1c52e0f7f1c4f36627b31b6a4d/tikzplotlib/_save.py#L254 does not create a UTF-8 file per default.

Aikhjarto avatar May 24 '20 17:05 Aikhjarto