Search code examples
pandasdataframegraphlabelpie-chart

Showing one label on pie chart pandas


Is there a way of showing just one set of label? At the moment it is looking very messy and I would like to have one set of label please. I did label=None and it turned off all the labels. enter image description here

Thanks


Solution

  • I think you need a bit change How to make MxN piechart plots with one legend and removed y-axis titles in Matplotlib:

    df = pd.DataFrame({'beer':[1,2,3],
                       'spirit':[4,5,6],
                       'wine':[7,8,9]}, index=['Africa','Asia','Europe'])
    
    print (df)
            beer  spirit  wine
    Africa     1       4     7
    Asia       2       5     8
    Europe     3       6     9
    
    fig, axes = plt.subplots(1,3, figsize=(10,3))
    for ax, idx in zip(axes, df.index):
        ax.pie(df.loc[idx], labels=df.columns, autopct='%.2f')
        ax.set(ylabel='', title=idx, aspect='equal')
    
    axes[0].legend(bbox_to_anchor=(0, 0.5))
    plt.show()
    

    graph