Reversed Data in Pie Chart

Hello Plotly friends, hope you an help me here :wave:!

The data in the pie chart below is reversed for Americas and EMEA values, I have another pie chart with another column and works just fine, obviously I’m doing something wrong here but I can’t see it.

Thank you for your help!

labels = df['Theater'].unique()
values = df['Theater'].value_counts()
customerTheaterFig = go.Figure(
data=[go.Pie(labels=labels, values=values, hole=.4)],
layout=dict(title=dict(text="<b>Customer Theater</b> (All)")))

customerTheaterFig.show()

The value_counts() method of pandas returns value in descending order, so the highest value (371) would be at the first position in your values. Whereas the labels are in the order as per the df.

Use can try this:

dff = df['Theater'].value_counts()

customerTheaterFig = go.Figure(
data=[go.Pie(labels=dff.index, values=dff.values, hole=.4)],
layout=dict(title=dict(text="<b>Customer Theater</b> (All)")))

customerTheaterFig.show()

Thank you so much @atharvakatre!
I’ll try it out as soon as possible, I’ll reply here with updates.

1 Like

Worked great!
Thank you @atharvakatre!

1 Like