Python – Matplotlib-Fehler beim Erstellen eines Kreisdiagramms
过去多啦不再A梦
过去多啦不再A梦 2017-06-12 09:23:57
0
1
946
def plot_graph():
    lables = '男生比例','女生比例','其他'
    sizes = get_friends_rate()
    plt.pie(sizes, lables, autopct='%.3f%%', shadow=False, startangle=90)
    plt.axis('equal')
    plt.show()
plot_graph()

Wo def get_friends_rate() zurückgibt
return [float(male)/total 100, float(female)/total 100, float(other)/total * 100]
Während des Vorgangs ist ein Fehler aufgetreten:

过去多啦不再A梦
过去多啦不再A梦

Antworte allen(1)
世界只因有你

使用了如下的源码:

>>> from matplotlib import pyplot as plt
>>> sizes = 30,20,50
>>> lables = u'男生比例',u'女生比例',u'其他'
>>> plt.pie(sizes, labels=lables,autopct='%.3f%%', shadow=False, startangle=90)
>>> plt.axis('equal')
>>> plt.show()

在这里把标签使用labels参数传入即可,这里使用的是Python2.7进行编写。由于是中文,会出现无法显示的问题。

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!