กราฟโดนัทเป็นกราฟวงกลมชนิดหนึ่งที่ใช้แสดงสัดส่วนตามหมวดหมู่ โดยเว้นช่องว่างไว้ตรงกลาง ช่องว่างนี้ไม่มีความหมายพิเศษ แต่สามารถใช้แสดงสถิติภาพรวมได้ (เช่น “ยอดรวม XXX บาท”) กราฟโดนัทสร้างใน Python ได้ด้วย matplotlib.pyplot.pie
import matplotlib.pyplot as plt
# Data
percent = [40, 20, 20, 10, 10]
explode = [0, 0, 0, 0, 0]
labels = ["??", "??????", "??", "??", "???"]
percent.reverse()
explode.reverse()
labels.reverse()
# Create pie chart
plt.figure(figsize=(7, 7))
plt.pie(x=percent, labels=labels, explode=explode, autopct="%1.0f%%", startangle=90)
# Add a blank circle in the middle
background_color = "#fff"
p = plt.gcf()
p.gca().add_artist(plt.Circle((0, 0), 0.8, color=background_color))
plt.show()
