I\'d like to create a matplotlib pie chart which has the value of each wedge written on top of the wedge.
The documentation suggests I should use autopct
With the help of matplotlib gallary and hints from StackOverflow users, I came up with the following pie chart. the autopct shows amounts and kinds of ingredients.
import matplotlib.pyplot as plt
%matplotlib inline
reciepe= ["480g Flour", "50g Eggs", "90g Sugar"]
amt=[int(x.split('g ')[0]) for x in reciepe]
ing=[x.split()[-1] for x in reciepe]
fig, ax=plt.subplots(figsize=(5,5), subplot_kw=dict(aspect='equal'))
wadges, text, autotext=ax.pie(amt, labels=ing, startangle=90,
autopct=lambda p:"{:.0f}g\n({:.1f})%".format(p*sum(amt)/100, p),
textprops=dict(color='k', weight='bold', fontsize=8))
ax.legend(wadges, ing,title='Ingredents', loc='best', bbox_to_anchor=(0.35,0.85,0,0))
Piechart showing the amount and of percent of a sample recipe ingredients
Pie chart showing the salary and percent of programming Language users