我的问题,当标签包含土耳其字符如ş,ö,ü,İ,Ğ,ğ
时,我无法绘制它只是给出了这个输出 - > matplotlib.figure.Figure at 0x7f8499386050 not not the graph
我该如何解决?
这是我的代码:
def draw_pie(year,y,by):
v=data[data['yil']==year]
v=v.sort(y,ascending=False).head(20)
v=v.groupby(by).aggregate('sum')
veri= v[ y ]
veri.plot(figsize=(10,10),kind='pie', labels=v.index,
autopct='%.2f', fontsize=20)
plt.show()
draw_pie(2014,'toplam_hasilat','tur')
不显示beacuse tur包含'Aşk','Gençlik'
没有土耳其人的角色也没关系。
提前谢谢
答案 0 :(得分:2)
假设您决定使用通用编码:
首先必须告诉源编码是utf-8(下面的第一行)。然后你必须将字符串解码为utf-8。如果python3它应该工作,如果python2你可以告诉它行为像python3:
示例(Python 2.7.8)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import matplotlib.pyplot as plt
plt.plot(range(10), range(10))
plt.title("Simple Plot şöüİĞğ")
plt.show()
您也可以明确地解码每个字符串,但这可能不太方便(下面的两个解决方案)
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
plt.plot(range(10), range(10))
plt.title("Simple Plot şöüİĞğ".decode('utf-8'))
plt.xlabel(u"Simple Plot şöüİĞğ")
plt.show()
答案 1 :(得分:0)
我已将解决方案用于我的问题,如下所示。
我试图用土耳其字体从Excel读取数据。在我的Jupyter noteboook中绘制数据时,Pandas失败了。然后我添加了
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
在第一个单元格中,运行所有单元格。然后我得到了我的阴谋。