vs code encoding conflict between Output and matplotlib for french accents

71 views Asked by At

when I prefix my .py file using utf-8 or Latin-1 I always get bad charcacters in OUTPUT or in matplotlib figure text.

Post 'Working with UTF-8 encoding in Python source' does not answer my question which is specific to vs code.

In:

`# -*- coding: utf-8 -*-`
print('à')

Out:

matplotlib text with utf-8 encoding right display > matplotlib text with utf-8 encoding right display

In:

`# -*- coding: Latin-1 -*-`
print('à')

Out:

à

matplotlib text with Latin-1 wrong display > matplotlib text with Latin-1 wrong display

I tried different encodings but I never get proper outputs

2

There are 2 answers

0
fran6 On BEST ANSWER

In vs code, I've checked Preferences > Settings > code runner : Run in Terminal so I no longer need to use the utf-8 code substitute in the plain text, I can now write "à" or any accentuated letter directly so OUTPUT and matplotlib are OK.

1
fran6 On

Thank you JosefZ.

I adopt UTF-8 everywhere.

print('\xc3\xa0') fixed the issue.

print('à'.encode('utf-8')) to find the code.

I you have better solution configuring matplotlib avoiding to use codes, I'll take it.