Donut Plot


A Donut chart is essentially a Pie Chart with an area of the center cut out. You can build one hacking the plt.pie() function of the matplotlib library as shown in the examples below.

⏱ Quick start

matplotlib allows to build a pie chart easily thanks to its pie() function. Visit the dedicated section for more about that.

We can use the exact same principle and add a circle to the center thanks to thecircle() function and get a donut chart.🔥

# library
import matplotlib.pyplot as plt

# create data
size_of_groups=[12,11,3,30]

# Create a pieplot
plt.pie(size_of_groups)

# add a circle at the center to transform it in a donut chart
my_circle=plt.Circle( (0,0), 0.7, color='white')
p=plt.gcf()
p.gca().add_artist(my_circle)

plt.show()

⚠️ Mind the donut!

As his friend the Pie chart, the Donut chart is often criticized. Humans are pretty bad at reading angles, making it hard to rank the groups accurately. Most of the time, it is better to display the information as a barchart, a treemap or a lollipop plot.

Have a look to the 3 pie charts below, can you spot the pattern hidden in it?

Matplotlib logoDonut plot with Matplotlib

The example above is a good start but you probably need to go further. The blog posts linked below explain common tasks like adding and customizing labels, change section colors, add padding between each and more.

Contact

👋 This document is a work by Yan Holtz. Any feedback is highly encouraged. You can fill an issue on Github, drop me a message onTwitter, or send an email pasting yan.holtz.data with gmail.com.

Violin

Density

Histogram

Boxplot

Ridgeline

Scatterplot

Heatmap

Correlogram

Bubble

Connected Scatter

2D Density

Barplot

Spider / Radar

Wordcloud

Parallel

Lollipop

Circular Barplot

Treemap

Venn Diagram

Donut

Pie Chart

Dendrogram

Circular Packing

Line chart

Area chart

Stacked Area

Streamgraph

Timeseries with python

Timeseries

Map

Choropleth

Hexbin

Cartogram

Connection

Bubble

Chord Diagram

Network

Sankey

Arc Diagram

Edge Bundling

Colors

Interactivity

Animation with python

Animation

Cheat sheets

Caveats

3D