import matplotlib.pyplot as plt
plt.pie(x, explode=None, labels=None, colors=None, autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1,
startangle=0, radius=1, counterclock=True, wedgeprops=None, textprops=None, center=0, 0, frame=False,
rotatelabels=False, *, normalize=None, data=None)
常用参数:
x
即每个扇形的占比的序列或数组explode
如果不是None,则是一个len(x)长度的数组,指定每一块的突出程度;突出显示labels
为每个扇形提供标签的字符串序列colors
为每个扇形提供颜色的字符串序列autopct
如果它是一个格式字符串,标签将是fmt % pct。如果它是一个函数,它将被调用。shadow
阴影startangle
从x轴逆时针旋转,饼的旋转角度
import matplotlib.pyplot as plt
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' # 定义标签
sizes = [15, 30, 45, 10] # 每一块的比例
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral'] # 每一块的颜色
explode = (0, 0.1, 0, 0) # 突出显示,这里仅仅突出显示第二块(即'Hogs')
plt.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90)
plt.axis('equal') # 显示为圆(避免比例压缩为椭圆)
plt.show()
如果对您有帮助,麻烦点赞关注,这真的对我很重要!!!如果需要互关,请评论留言!