Pie Chart

I. Create a pie chart

We can create a pie chart with plt.pie.

budget = [50, 10, 7.5, 30, 10]
plt.pie(budget)
plt.axis('equal') # Set the axes to be equal 
plt.show()

II. Lable pie chart

We can use labels keyword to display category names of each slice

plt.pie(budget, labels=budget_categories)

To display the percentage of the total that each slice occupies, we use keyword autopct and pass in a string format:

  • ‘%d%%': round the the nearest interger with the percentage sign. Ex: 2
  • ‘%0.1f’: 1 decimal. Ex: 2.4
  • ‘%0.1f%%': 1 decimal with percentage sign. Ex: 2.4%
plt.pie(budget, labels=budget_categories, autopct='%0.1f')