python making pie chart

  The source code is as follows:

import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif']='SimHei'#设置中文显示
plt.figure(figsize=(6,6))#调节图片大小,如果将画布设定为正方形,则绘制的饼图是正圆
label=['第一','第二','第三']#定义饼图的标签,标签是列表
#explode=[0.01,0.01,0.01] #设定各项距离圆心n个半径,当三项相等的时候均值显示
#explode=[0,0.2,0] #第二部分突出

#plt.pie(values[-1,3:6],explode=explode,labels=label,autopct='%1.1f%%')#绘制饼图
values=[4,7,9] #饼图数据,只要输入数据即可。比例自动划分
#通过colors变量可指定颜色,可用默认颜色如'r' 'b' 'g', 也可以使用RGB,python中RGB值都是[0,1],可通过除以255来实现
# #color=['r','b','g']
color=[[255/255, 165/255, 0/255],'b','g']
plt.pie(values,explode=explode,labels=label,autopct='%1.1f%%',colors=color)#绘制饼图
plt.title('饼图')#绘制标题
plt.show()
#plt.savefig('饼图')#保存图片

  The effect of the equal distance fan chart is as follows:
Insert picture description here
  some of the effects of the prominent fan chart are as follows:
Insert picture description here
refer to the blog: https://blog.csdn.net/sunflower_sunuo/article/details/80572296

Guess you like

Origin blog.csdn.net/gls_nuaa/article/details/112902085