skip to Main Content

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

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

Answers


  1. Chosen as BEST ANSWER

    Thank you JosefZ.

    I adopt UTF-8 everywhere.

    print('xc3xa0') 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.


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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search