文章详情页
python - matplotlib 做一个饼状图出错
浏览:190日期: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. javascript - ueditor引入报错问题2. html5 - 响应式WEB,媒体查询的问题。3. 关docker hub上有些镜像的tag被标记““This image has vulnerabilities””4. boot2docker无法启动5. dockerfile - [docker build image失败- npm install]6. nignx - docker内nginx 80端口被占用7. docker start -a dockername 老是卡住,什么情况?8. docker容器呢SSH为什么连不通呢?9. angular.js - angular内容过长展开收起效果10. dockerfile - 为什么docker容器启动不了?
排行榜

网公网安备