Super learner
This user is a Super Learner. To become a Super Learner, you need to reach Level 8.
Pie chart showing Real value
in
The Complete Data Visualization Course with Python, R, Tableau, and Excel
/
Pie Chart - Python - How to Create a Pie Chart
How can I show the real value instead of percentage?
2 answers ( 0 marked as helpful)
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.
Thank you very much, appreciated