Home > Software engineering >  How do I rearrange the order of pie slices in pandas plot?
How do I rearrange the order of pie slices in pandas plot?

Time:01-17

I am trying to rearrange the order of the pie slices in my pie chart. I am relatively new to Python and am having trouble figuring this out. Here is my current code:

df.groupby(['Country']).sum().plot(kind='pie', y='Alcohol_Consumption', subplots=True, shadow = True,startangle=-270,
figsize=(15,10), autopct='%1.1f%%', counterclock=False,)

plt.show()

The pie chart slices arrange in alphabetical order by the names of the countries, even though my dataframe is different. So, how do I change the order of the pie chart slices to be the same as the dataframe?

Here is the resulting pie chart:

resulting pie chart

Dataframe: reordering pie chart wedges in pandas

  •  Tags:  
  • Related