Donut Plot with Python

The Donut plot is similar to a pie chart, except it has a hole in the middle similar to a donut. In this article, I will walk you through how to create a Donut Plot with the Python programming language.

What are Donut Plots?

donut plots

Donut plots are pie charts with a hole. All the functionality of a pie chart is also available on the donut chart. However, the donut chart has additional capabilities regarding the hole.

Also, Read -100+ Machine Learning Projects Solved and Explained.

The data portion of the donut chart is called the “donut”. By default, the ring size is 30% of the ring radius, which means the hole occupies 70%. These percentages are the default values, regardless of the size of the donut. The central hole allows you to inject additional information into the graph.

Donut Plot with Python

Now, in this section, I will take you through how to create a donut plot with Python programming language. For this task, I will use the data on Covid-19 spread in India. So let’s get started with the task of creating donut plots with Python by importing the necessary libraries and the dataset:

import pandas as pd
df = pd.read_json("datanew.json")
covid 19 data

I will first create a donut plot with Python by using the matplotlib library for visualizing the Total Positive, Active, and Cured Cases:

donut plot on covid 19 cases

The last row in the dataset is an outlier so I will delete the row and then, I will sort the values according to the highest active cases:

df.drop(df.tail(1).index, inplace = True) 
df1 = df.sort_values(by='active', ascending=False)
df3 = df1[:5]

Now, I will create a donut plot with Python to visualize the top 5 states in India with the highest active cases of Covid 19:

donut plot on top 5 states

I hope you liked this article on how to create donut plots with Python programming language. 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: 1498

Leave a Reply