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

UnicodeDecodeError in IPython Notebook caused by negative numbers in plt.legend() #5499

Closed
goulu opened this issue Nov 17, 2015 · 2 comments
Closed

Comments

@goulu
Copy link

goulu commented Nov 17, 2015

Encountered a strange error shown in a small IPython Notebook here : https://gist.github.com/goulu/ba518d1a0a5267c0d3f3

in the method repr_svg method that generates a svg plot for IPython Notebook ( 2.7 kernel )

plt.legend()
savefig(output, format='svg')

generates content like

<!-- \xe2\x88\x925 --> 

for "-5" in the legend, which causes a UnicodeDecodeError in JSON via Jupyter client

@jenshnielsen
Copy link
Member

The svg output contains unicode characters so that can't we written to a bytesIO object which cannot handle svg files. Is there any reason that you cannot use a StringIO object which handles unicode objects

@goulu
Copy link
Author

goulu commented Nov 17, 2015

I used BytesIO because the same rendering method also generates png, but I'll definitely have a look at StringIO, thanks.

In the meantime I solved my problem by adding a .decode('utf-8') at the end of the repr_svg method. Sorry for the noise ...

@goulu goulu closed this as completed Nov 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants