文章詳情頁
python - matplotlib 做一個餅狀圖出錯
瀏覽:96日期: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]運行出現錯誤:
問題解答
回答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進行編寫。由于是中文,會出現無法顯示的問題。
相關文章:
1. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?2. MySQL數據庫中文亂碼的原因3. macos - mac下docker如何設置代理4. docker不顯示端口映射呢?5. 關docker hub上有些鏡像的tag被標記““This image has vulnerabilities””6. java - 請問在main方法中寫成對象名.屬性()并賦值,與直接參參數賦值輸錯誤是什么原因?7. css - C#與java開發Windows程序哪個好?8. android studio總是在processes running好久9. angular.js - 關于$apply()10. docker 17.03 怎么配置 registry mirror ?
排行榜
