您的位置:首頁技術文章
文章詳情頁

python - matplotlib 做一個餅狀圖出錯

瀏覽:111日期:2022-06-29 13:41:13

問題描述

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()

其中def get_friends_rate()返回return [float(male)/total 100, float(female)/total 100, float(other)/total * 100]運行出現錯誤:

python - matplotlib 做一個餅狀圖出錯

問題解答

回答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進行編寫。由于是中文,會出現無法顯示的問題。

標簽: Python 編程
相關文章:
国产综合久久一区二区三区