如何调整饼图的标签

2024-09-30 14:34:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建一个饼图,以在列["PTypes"]中显示数据集中可用属性类型的百分比。我使用了下面的代码

    `import matplotlib.pyplot as plt
    # Pie chart
df['PType'].value_counts().plot(kind='pie', autopct='%1.1f%%', pctdistance=1, labeldistance=1.3, fontsize=12, figsize=(8,6))

   plt.pie(sizes, colors = colors, autopct='%1.1f%%', startangle=90, pctdistance=0.85, explode = explode)
    #draw circle
    centre_circle = plt.Circle((0,0),0.70,fc='white')
    fig = plt.gcf()
    fig.gca().add_artist(centre_circle)
    # Equal aspect ratio ensures that pie is drawn as a circle
    ax.axis('equal')  
    plt.tight_layout()
    plt.show()`

这就是它产生的结果

enter image description here

是的,我知道这看起来有点奇怪。我需要调整标签,去掉顶部的红色背景,并引入一个图例

我该怎么做


Tags: 数据类型属性asfigplt百分比colors