文章詳情頁
python - matplotlib 做一個餅狀圖出錯
瀏覽:132日期: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. javascript - 關于apply()與call()的問題2. html - eclipse 標簽錯誤3. python - Pycharm的Debug用不了4. javascript - axios請求回來的數據組件無法進行綁定渲染5. Python中使用超長的List導致內存占用過大6. python - pandas按照列A和列B分組,將列C求平均數,怎樣才能生成一個列A,B,C的dataframe7. 安全性測試 - nodejs中如何防mySQL注入8. javascript - JS變量被清空9. java - 在用戶不登錄的情況下,用戶如何添加保存到購物車?10. javascript - 有適合開發手機端Html5網頁小游戲的前端框架嗎?
排行榜
