Pie Charts using Python

A pie chart is created by dividing a circle into two or more sections depending on the number of entities we want to visualize. It is used to analyze the proportion of each entity among all the entities. In this article, I’ll walk you through how to visualize pie charts using Python.

Pie Charts using Python

A pie chart is used to analyze the distribution of data and the proportion of each feature in the data set. Now let’s see how to visualize a simple pie chart using Python, before implementing it on a real dataset. The pyplot.pie() function of the matplotlib library can be used to visualize a pie chart:

simple pie chart
A Simple Pie Chart using Matplotlib

In the code above, the pyplot.pie() function takes a list of input values and visualizes a simple pie chart. So it was just a simple pie chart, now let’s see how to visualize pie charts using Python using realtime dataset.

Also, Read – 200+ Machine Learning Projects solved and Explained.

Here I will use the Covid-19 dataset to visualize the proportion of active, positive, and cured cases in India according to the dataset:

Proportion of active, positive and cured cases
Proportion of active, positive and cured cases

Now let’s visualize the distribution of top 5 cities with active cases of covid-19 in India:

Proportion of top 5 cities with active cases
Proportion of top 5 cities with active cases

With some modifications we can turn a pie chart into a donut plot, you can learn more about it from here.

Summary

A pie chart is going to help you when you want to analyze the proportion of a feature among all the feature. You can also select two or more features that we just saw in this article for visualizing a pie chart. 

So this is how we can create beautiful and customized pie charts using the matplotlib library in Python. I hope you liked this article on how to visualize pie charts with Python. Feel free to ask your valuable questions in the comments section below.

Aman Kharwal
Aman Kharwal

I'm a writer and data scientist on a mission to educate others about the incredible power of data📈.

Articles: 1538

Leave a Reply