python - matplotlib 做一個餅狀圖出錯
問題描述
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]運行出現(xiàn)錯誤:

問題解答
回答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()
在這里把標(biāo)簽使用labels參數(shù)傳入即可,這里使用的是Python2.7進(jìn)行編寫。由于是中文,會出現(xiàn)無法顯示的問題。
相關(guān)文章:
1. boot2docker無法啟動2. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””3. docker-compose中volumes的問題4. nignx - docker內(nèi)nginx 80端口被占用5. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.6. java - SSH框架中寫分頁時service層中不能注入分頁類7. golang - 用IDE看docker源碼時的小問題8. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?9. javascript - mock.js可以存儲數(shù)據(jù)嗎10. docker api 開發(fā)的端口怎么獲???

網(wǎng)公網(wǎng)安備