5

matplotlib でタイトルを正しく取得できません: 次のようになり 'technologieën in °C'ます:technologieÃn in ÃC

可能な解決策はすでに試しました:

  • u'technologieën in °C動作しません
  • どちらもしません:# -*- coding: utf-8 -*-コードファイルの先頭に。

解決策はありますか?

4

2 に答える 2

12

You need to pass in unicode text:

u'technologieën in °C'

Do make sure you use the # -*- coding: utf-8 -*- comment at the top, and make sure your text editor is actually using that codec. If your editor saves the file as Latin-1 encoded text, use that codec in the header, etc. The comment communicates to Python how to interpret your source file, especially when it comes to parsing string literals.

Alternatively, use escape codes for anything non-ASCII in your Unicode literals:

u'technologie\u00ebn in \u00b0C'

and avoid the issue of what codec to use in the first place.

I urge you to read:

before you continue.

Most fonts will support the °, but if you see a box displayed instead, then you have a font issue and need to switch to a font that supports the characters you are trying to display. For example, if Ariel supports your required characters, then use:

matplotlib.rc('font', family='Arial')

before plotting.

于 2013-07-08T11:52:41.657 に答える
0

Python3 では、面倒な UTF-8 の問題を心配する必要はありません。

プロットする前に Unicode フォントを設定する必要があることに注意してください。

matplotlib.rc('font', family='Arial')

于 2017-03-17T09:18:53.210 に答える