Jom*_*mme 5 python unicode matplotlib spyder
无法在matplotlib中获得正确的标题:
'technologieën in °C'
给出:technologieÃn in ÃC
已经尝试过的可能解决方案:
u'technologieën in °C
'不起作用,也不起作用:# -*- coding: utf-8 -*-
在代码文件的开头.有解决方案吗
Mar*_*ers 11
您需要传入unicode文本:
u'technologieën in °C'
Run Code Online (Sandbox Code Playgroud)
确保使用# -*- coding: utf-8 -*-
顶部的注释,并确保文本编辑器实际使用该编解码器.如果编辑器将文件保存为Latin-1编码文本,请在标题中使用该编解码器等.注释向Python传达如何解释源文件,特别是在解析字符串文字时.
或者,在Unicode文字中使用任何非ASCII的转义码:
u'technologie\u00ebn in \u00b0C'
Run Code Online (Sandbox Code Playgroud)
并避免首先使用什么编解码器的问题.
我恳请你阅读:
绝对最低每个软件开发人员绝对必须知道关于Unicode和字符集(没有任何借口!)作者:Joel Spolsky
Ned Batchelder的实用Unicode
在你继续之前.
大多数字体都支持°
,但是如果你看到一个显示的框,那么你就会遇到字体问题,需要切换到支持你试图显示的字符的字体.例如,如果Ariel支持您所需的字符,那么使用:
matplotlib.rc('font', family='Arial')
Run Code Online (Sandbox Code Playgroud)
在绘图之前.