文章详情页
python - matplotlib 做一个饼状图出错
浏览:118日期: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]运行出现错误:
问题解答
回答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进行编写。由于是中文,会出现无法显示的问题。
相关文章:
1. mysql - 用PHPEXCEL将excel文件导入数据库数据5000+条,本地数据库正常,线上只导入15条,没有报错,哪里的问题?2. docker - 如何修改运行中容器的配置3. angular.js - angularJs ngRoute怎么在路由传递空字符串及用ng-switch取得4. dockerfile - [docker build image失败- npm install]5. 在windows下安装docker Toolbox 启动Docker Quickstart Terminal 失败!6. 为什么我ping不通我的docker容器呢???7. nignx - docker内nginx 80端口被占用8. docker绑定了nginx端口 外部访问不到9. docker不显示端口映射呢?10. docker-compose中volumes的问题
排行榜
