文章詳情頁
python - matplotlib 做一個餅狀圖出錯
瀏覽:144日期: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. android - weex 項目createInstanceReferenceError: Vue is not defined2. android - 哪位大神知道java后臺的api接口的對象傳到前端后輸入日期報錯,是什么情況?求大神指點3. PHPExcel表格導入數據庫怎么導入4. pdo 寫入到數據庫的內容為中文的時候寫入亂碼5. javascript - 如圖,百度首頁,查看源代碼為什么什么都沒有?6. vue2.0+webpack 如何使用bootstrap?7. PHP類封裝的插入數據,總是插入不成功,返回false;8. mac連接阿里云docker集群,已經卡了2天了,求問?9. 微信渠道二維碼怎么使用?10. html5 - html元素select下拉列表在原生app里面為什么不能彈框顯示?
排行榜
