Radially displace pie chart wedge in Matplotlib

Python

Matplotlib

Pie

Explode wedge

Luc B.

Python

Matplotlib

Pie Chart

With a pie chart, it is often useful to emphasize a particular wedge by removing it from the pie. This is called exploding the wedge, and it's easy to do in Matplotlib.

Code Example

Use the explode argument to plt.pie() to explode a particular wedge. explode is an array that specifies the fraction of the pie raius to displace each wedge.

import matplotlib.pyplot as plt

labels = ['Python', 'MATLAB', 'R', 'Julia']
values = [60, 20, 32, 13]
displace = [0, 0, 0, 0.2]

# Create pie chart here
plt.pie(values, labels=labels, explode=displace)

plt.show()

png