python饼状图介绍及绘制饼状图

498次阅读
没有评论

python饼状图介绍及绘制饼状图

python绘制饼状图

1、用于表示不同分类的比例,通过弧度大小比较各种分类。

2、pie函数可以绘制饼图,饼图主要用于表现比例。只需输入比例数据即可。

python绘制饼状图语法

plt.pie(x, labels=,autopct=,colors)

python饼状图绘制实例

#导入模块
import matplotlib.pyplot as plt
import numpy as np
#准备男、女的人数及比例
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%%')
 
#设置饼状图中的字体颜色
for text in autotexts:
    text.set_color('white')
 
#设置字体大小
for text in texts+autotexts:
    text.set_fontsize(20)
plt.show()
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2022-03-14发表,共计680字。
新手QQ群:570568346,欢迎进群讨论 Python51学习