python饼图怎么画(python饼状图的介绍及绘制)
导读:说明...
说明
1 、用于表示不同分类的比例 ,通过弧度大小比较各种分类 。
2 、pie函数可以绘制饼图 ,饼图主要用于表现比例 。只需输入比例数据即可 。
语法
plt.pie(x,labels=,autopct=,colors)实例
#导入模块 importmatplotlib.pyplotasplt importnumpyasnp #准备男 、女的人数及比例 man=71351 woman=68187 man_perc=man/(woman+man) woman_perc=woman/(woman+man) #添加名称 labels=[男,女] #添加颜色 colors=[blue,red] #绘制饼状图pie plt.rcParams[font.sans-serif]=[SimHei]#用来正常显示中文标签 #labels名称colors:颜色 ,explode=分裂autopct显示百分比 paches,texts,autotexts=plt.pie([man_perc,woman_perc],labels=labels,colors=colors,explode=(0,0.05),autopct=%0.1f%%) #设置饼状图中的字体颜色 fortextinautotexts: text.set_color(white) #设置字体大小 fortextintexts+autotexts: text.set_fontsize(20) plt.show()以上就是python饼状图的介绍及绘制 ,希望对大家有所帮助 。更多Python学习指路:Python基础教程
创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!