Adding percentage to pie chart Mathplotlib

Author: Al-mamun Sarkar Date: 2020-04-02 17:48:35

Adding percentage to pie chart Mathplotlib. The following codes shows how to add percentage to Pie Chart using python mathplotlib module.

 

Import Module:

import matplotlib.pyplot as plt

 

Create Data:

slices_data = [70,20,20,130]
all_activities = ['sleeping','eating','working','playing']

 

Creating pie chart and adding percentage:

plt.pie(slices_data, 
        labels=all_activities, 
        colors=colors,
       startangle=90,
       shadow = True,
       explode=(0, 0.2, 0, 0),
       autopct='%1.1f%%')
plt.title("Welcome to pie chart tutorial")
plt.xlabel('X-Axis')
plt.ylabel('Y-Axis')
plt.legend()
plt.show()