Pie Plot


A Pie Chart is a circle divided into sectors that each represent a proportion of the whole. It is one of the most common viz type, but also probably the most criticized. In python, they are most of the time done thanks to the pie() function of the Matplotlib library.

⏱ Quick start

matplotlib allows to build a pie chart easily thanks to its pie() function.

The input data you must provide is an array of numbers, where each numbers will be mapped to one of the pie item.🔥

# library
import matplotlib.pyplot as plt

# create data: an array of values
size_of_groups=[12,11,3,30]

# Create a pieplot
plt.pie(size_of_groups)
plt.show()

⚠️ Mind the pie chart

Pie chart is probably the most criticized chart type. 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?

Last but not least, please avoid the explode and shadow options of the pie() function, they are killing all the most basic dataviz principles.

Matplotlib logoPie chart with Matplotlib

The examples below should guide you through the pie() function usage. It starts basics and then show how to add labels, customize colors 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

Map

Choropleth

Hexbin

Cartogram

Connection

Bubble

Chord Diagram

Network

Sankey

Arc Diagram

Edge Bundling

Colors

Interactivity

Animation with python

Animation

Cheat sheets

Caveats

3D