pythonmatplotlibvisual-studio-codecharacter-encodingmojibake

vs code encoding conflict between Output and matplotlib for french accents


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


Solution

  • 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.