In this tutorial, you will learn to create custom pie chart #3 in python. First, you need to import matplotlib in order to continue this tutorial. The source code is show below.
import matplotlib.pyplot as plt # Pie chart labels = ['Frogs', 'Hogs', 'Dogs', 'Logs'] sizes = [15, 30, 45, 10] #colors colors = ['#ff9999','#66b3ff','#99ff99','#ffcc99'] #explsion explode = (0.05,0.05,0.05,0.05) plt.pie(sizes, colors = colors, labels=labels, autopct='%1.1f%%', startangle=90, pctdistance=0.85, explode = explode) #draw circle centre_circle = plt.Circle((0,0),0.70,fc='white') fig = plt.gcf() fig.gca().add_artist(centre_circle) # Equal aspect ratio ensures that pie is drawn as a circle ax1.axis('equal') plt.tight_layout() plt.show()
The output you get will be: