Pie charts allow us to see groups of a whole. For example, let's say we have a marketing budget of $100k. Then, we have a list of expense by ad types (FB ads, Google Ads, TV ads, Newspaper Ads). We can use a pie chart to see how much of each add type we spent of the total budget. In this article, we will see how to create a Pie chart to display this data in MatPlotLib.
To create a pie chart, we need the labels of categories (which in this example are the different ads). We also need the percentage of each category. For example, we have 40 as the first item which represents that we spent 40% of the budge on Facebook Ads. We can then use the
pie function from
import matplotlib.pyplot as plt labels = [ 'Facebook', 'Google', 'TV', 'NewsPaper' ] sizes = [40, 30, 10, 20] plt.pie(sizes, labels = labels) plt.show()