久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

python - matplotlib 做一個餅狀圖出錯

瀏覽:135日期: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]運(yùn)行出現(xiàn)錯誤:

python - matplotlib 做一個餅狀圖出錯

問題解答

回答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)無法顯示的問題。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 临湘市| 镇赉县| 崇义县| 福鼎市| 大石桥市| 巢湖市| 万荣县| 镇江市| 玉溪市| 民勤县| 泾阳县| 文登市| 柳林县| 焉耆| 通山县| 内黄县| 德惠市| 宣汉县| 应城市| 遵化市| 湘阴县| 泽普县| 杭锦后旗| 静海县| 泗洪县| 确山县| 祁连县| 大港区| 翁牛特旗| 衡东县| 那坡县| 绥江县| 木里| 呼伦贝尔市| 新沂市| 玛纳斯县| 类乌齐县| 苏尼特右旗| 太仆寺旗| 南木林县| 湖南省|