文章详情页
python - matplotlib 做一个饼状图出错
浏览:176日期: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. html5 - vue.js中,如何对转义字符进行表达式判断?2. 为什么学习PHP3. javascript - es6 中map一次得到全部的values4. html5 - weex H5端的使用,怎么跑起来?5. javascript - webpack打包es6,模块加载的时候报错6. html - 急求,能否用flex或者高端点的CSS来布局这个图呢?不想用浮动或定位了7. 老哥们求助啊8. mysql - 现在已经使用CommandArgument取到t_ID的值,现在还想取t_Name的值一起放到cs文件中的sql语句中该怎么做9. CSS3可否做出这个效果?10. 就一台服务器,mysql数据库想实现自动备份,如何设计?
排行榜

网公网安备