国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

python - matplotlib 做一個餅狀圖出錯

瀏覽:117日期: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]運行出現錯誤:

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()

在這里把標簽使用labels參數傳入即可,這里使用的是Python2.7進行編寫。由于是中文,會出現無法顯示的問題。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 图片| 德格县| 江都市| 日照市| 精河县| 黎城县| 丹江口市| 黄浦区| 长沙市| 民乐县| 高陵县| 台前县| 元朗区| 灵宝市| 获嘉县| 万盛区| 电白县| 大英县| 石林| 章丘市| 武宁县| 克山县| 乌兰浩特市| 斗六市| 安顺市| 荃湾区| 阿拉尔市| 遵义县| 图们市| 鄂州市| 东乡族自治县| 黑河市| 江安县| 临西县| 来宾市| 革吉县| 罗城| 惠水县| 乌兰县| 乐昌市| 西乡县|