How do I use matplotlib autopct?

后端 未结 7 1662
野的像风
野的像风 2020-12-12 11:59

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

7条回答
  •  无人及你
    2020-12-12 12:11

    Using lambda and format may be better

    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns
    
    path = r"C:\Users\byqpz\Desktop\DATA\raw\tips.csv"
    
    df = pd.read_csv(path, engine='python', encoding='utf_8_sig')
    
    days = df.groupby('day').size()
    
    sns.set()
    days.plot(kind='pie', title='Number of parties on different days', figsize=[8,8],
              autopct=lambda p: '{:.2f}%({:.0f})'.format(p,(p/100)*days.sum()))
    plt.show()
    

提交回复
热议问题