【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()
运行结果:
【3x00】按角度调整扇形标签
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示例')
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中的五颜六色的饼状图!(二)
上一篇