方法描述[1x00]
matplotlib.pyplot.pie() 用于绘制饼状图的方法。
基本语法:
matplotlib.pyplot.pie( x[,explode=None,labels=None,colors=None, autopct=None,pctdistance=0.6,shadow=False, labeldistance=1.1,startangle=None,radius=None, counterclock=True,wedgeprops=None,textprops=None, center=(0,0),frame=False,rotatelabels=False,\*,data=None] )
简单示例[2x00]
importmatplotlib.pyplotasplt plt.rcParams['font.sans-serif']=['MicrosoftYaHei'] x=[10,30,45,15] labels=['Java','Golang','Python','C++'] colors=['red','yellow','blue','green'] #指定4个风扇区域的比例和风扇区域的颜色,风扇区域的文本标签距离风扇区域中心1.1 plt.pie(x,labels=labels,colors=colors,labeldistance=1.1) plt.title('饼状图简单示例') plt.show()
运行结果:
将扇形标签按角度调整
rotatelabels 可以设置每个蛋糕的属性是否可以从角度调整 label(标签)显示模式。
i
mportmatplotlib.pyplotasplt plt.rcParams['font.sans-serif']=['MicrosoftYaHei'] x=[10,30,45,15] labels=['Java','Go','Python','C++'] colors=['red','yellow','blue','green'] #指定4个风扇区域的比例和风扇区域的颜色。风扇区域的文本标签距离风扇区域中心1.1,并根据角度调整labels plt.pie(x,labels=labels,colors=colors,labeldistance=1.1,rotatelabels=True) plt.title('饼状图按角度调整labels示例#39;) plt.show()
运行结果:
显示图例[4x00]
importmatplotlib.pyplotasplt plt.rcParams['font.sans-serif']=['MicrosoftYaHei'] x=[10,30,45,15] labels=['Java','Go','Python','C++'] colors=['red','yellow','blue','green'] plt.pie(x,labels=labels,colors=colors,labeldistance=1.1) plt.title('饼状图显示图示示示例;) plt.legend(bbox_to_anchor=(1,1)) plt.show()
运行结果:
更多Python知识,请关注Python视频教程!!
相关推荐:
Python中五颜六色的饼状图!(二)