Super learner
This user is a Super Learner. To become a Super Learner, you need to reach Level 8.
Last answered:

02 Sept 2023

Posted on:

24 Aug 2023

0

Pie chart showing Real value

How can I show the real value instead of percentage?

2 answers ( 0 marked as helpful)
Instructor
Posted on:

29 Aug 2023

0

Hi Sahar, 

thanks for reaching out! To change the percentages to actual values you must change the autopct parameter. Here is an example code, which uses the lambda function to calculate the actual numbers from the percentages. Let me know if you have any further questions. 

plt.figure(figsize = (10, 8))
plt.pie(df_fuel_engine_type['Number of Cars'], 
        labels = df_fuel_engine_type['Engine Fuel Type'].values,
        autopct = lambda p: '{:.0f}'.format(p * sum(df_fuel_engine_type['Number of Cars']) / 100),  # This change displays actual numbers
        textprops = {'size' : 'x-large',
                     'fontweight' : 'bold', 
                     'rotation' : '30',
                     'color' : 'w'})
plt.legend()
plt.title('Cars by Engine Fuel Type', fontsize = 18, fontweight = 'bold')
plt.show()

Best, 

365 Eli

 

Super learner
This user is a Super Learner. To become a Super Learner, you need to reach Level 8.
Posted on:

02 Sept 2023

0

Thank you very much, appreciated 

Submit an answer