The trick to plot a donut chart using matplotlib is to draw a pie plot and add a white circle in the middle of it. In order to draw a circle, you can use the Circle() function of matplotlib. The parameters passed to the function in the example below are:

  • (x,y) : center point of the circle
  • radius : radius of the circle
  • color : color of the circle

In the example, the add_artist() function is used to add the white circle on the axes of the pie chart. In order to get the current axes instance on the current figure, the gca() function is used and to get the current figure, the gcf() function is used.

# library
import matplotlib.pyplot as plt
# create data
# Create a pie plot
# add a white circle at the center
my_circle=plt.Circle( (0,0), 0.7, color='white')

# show the graph

Contact & Edit

👋 This document is a work by Yan Holtz. You can contribute on github, send me a feedback on twitter or subscribe to the newsletter to know when new examples are published! 🔥

This page is just a jupyter notebook, you can edit it here. Please help me making this website better 🙏!