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]運(yùn)行出現(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. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. javascript - 使用angular 的ui-sref 中出現(xiàn)了中文參數(shù),點(diǎn)擊跳轉(zhuǎn)后瀏覽器的地址欄里出現(xiàn)轉(zhuǎn)義后的%AE....%a%43. javascript - 用JS 七牛上傳圖片出現(xiàn)文件已存在的錯誤(file exists)4. java - 郵箱如何發(fā)送html內(nèi)容5. javascript - 求賜教:網(wǎng)易郵箱Web端模擬登錄看信的加密參數(shù)_ntes_nnid、_ntes_nuid6. html5 - 這個代碼顯示功能如何實(shí)現(xiàn)?7. css3 - 圖片等比例縮放8. java - ConcurrentHashMap中的get()方法為什么可以不加鎖?9. css3 - animation屬性,safari瀏覽器不支持相關(guān)效果10. 工作近5年,3年Java Web ,近2年前端,未來何去何從?
