Reputation: 61
The following code is for creating a pie chart that shows the number of purchases made by each person from the "Shipping Address Name" column. The 'labels' list contains the name of each person and the 'purchases' list contain the number of purchases each person has made.
labels = df['Shipping Address Name'].unique()
purchases = df['Shipping Address Name'].value_counts()
plt.pie(purchases, labels=labels, autopct='%.f')
plt.title('Purchases Per Person')
plt.axis('equal')
return plt.show()
This is what the 'purchases' list basically looks like:
Lilly 269
Rolf 69
Sandy 11
Dan 2
I am trying to have the values in the purchase list to be shown in the pie chart instead of the percentages from "autopct=%.f". Not sure what the easiest way for the 'autopct' function to do this is, so any help is appreciated.
Upvotes: 2
Views: 5385
Reputation: 150745
Try re-calculate the actual values by multiplying with the total purchases:
purchases = df['Shipping Address Name'].value_counts()
purchases.plot.pie(autopct=lambda x: '{:.0f}'.format(x*purchases.sum()/100) )
# also
# plt.pie(purchases, autopct=lambda x: '{:.0f}'.format(x*purchases.sum()/100))
Output:
Upvotes: 4