python - matplotlib 做一個(gè)餅狀圖出錯(cuò)
問題描述
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)錯(cuò)誤:

問題解答
回答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)行編寫。由于是中文,會(huì)出現(xiàn)無(wú)法顯示的問題。
相關(guān)文章:
1. mac里的docker如何命令行開啟呢?2. 為什么我ping不通我的docker容器呢???3. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題4. docker容器呢SSH為什么連不通呢?5. nignx - docker內(nèi)nginx 80端口被占用6. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””7. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問題。8. docker gitlab 如何git clone?9. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個(gè)是怎么回事????10. docker-compose 為何找不到配置文件?

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