Like in the previous tutorials, import the library Matplotlib.
Start by creating the variable Expenses.
The Expenses variable will hold the data frames Rent, Groceries,Payments and Other. These will be the categories of each Pie piece.
Next, set values for each portion and set the colors.
Finally, create the pie chart and call the plt.show() functions to view results.
import matplotlib.pyplot as plt
# labels
Expenses = ['Rent', 'Groceries', 'Payments', 'Other']
# portions
pie_slices = [5, 2, 6,8 ]
# label color
colors = ['blue', 'green', 'yellow', 'red']
#pie chart
plt.pie(pie_slices, labels = Expenses, colors=colors,
startangle=90, shadow = True, explode = (0.1, 0.1, 0.1, 0.1),
radius = 1.0, autopct = '%1.1f%%')
# plot legend
plt.legend()
# Calling plotting function
plt.show()
Output
