1.python 中文输出
<span style="font-family:Microsoft YaHei;">SyntaxError: Non-ASCII character '\xe4' in file X:/XXXXXXX.py on line 3, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details</span>
解决办法:在输出前面加上 # coding:utf-8
print('你好')
2.matplotlib 中文输出乱码
<span style="font-family:Microsoft YaHei;">Traceback (most recent call last):
File "E:/PythonProject/DecisionTree/main.py", line 21, in <module>
treePlotter.createPlot()
File "E:\PythonProject\DecisionTree\treePlotter.py", line 21, in createPlot
plt.ylabel('中文中文')
</span>
或
解决办法:在输出前加上
import matplotlib.font_manager as fm
myfont = fm.FontProperties(fname='C:/Windows/Fonts/msyh.ttc')
<span style="font-family:Microsoft YaHei;">plt.xlabel(u'中文',fontproperties=myfont)
plt.ylabel(u'中文',fontproperties=myfont)
plt.title(u'中文',fontproperties=myfont)</span>