文章详情页
python - matplotlib 做一个饼状图出错
浏览:45日期: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. node.js - nodejs中mysql子查询返回多行结果怎么处理?2. python3.x - python中import theano出错3. javascript - 我写的href跳转地址不是百度,为什么在有的机型上跳转到百度了,有的机型跳转正确4. 这段代码是获取百度收录量的!需要怎么设置才能获取百度快照旁边的网址呢?5. 设置python环境变量时不小心把原始path都删了,请问怎么恢复? win7 64位的6. python - mysql 如何设置通用型字段? 比如像mongodb那样7. mysql - spring data jpa 方法sql复杂查询?8. node.js - 微信的自动回复问题9. git - 使用淘宝npm安装hexo出现问题?10. python - pandas按照列A和列B分组,将列C求平均数,怎样才能生成一个列A,B,C的dataframe
排行榜