文章详情页
python - matplotlib 做一个饼状图出错
浏览:236日期: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. linux - python 安装 Anaconda 环境变量问题请教2. mysql插入文本如果是个sql语句就报错了3. javascript - 使用vue-cli有个报错ERR_INCOMPLETE_CHUNKED_ENCODING4. python中merge后文件莫名变得非常大5. mysql连表排序6. mysql - SQL添加记录的数据来源于同一个表7. mysql sql where id in(25,12,87) 结果集如何用按照 25 12 87排序?8. python3.x - python多线程如何修改数据?9. css3 - 没明白盒子的height随width的变化这段css是怎样实现的?10. html5 - 请问一下写H5的时候 你们都是兼容那些手机
排行榜

网公网安备