In [1]:
from matplotlib import pyplot as plt
In [3]:
plt.style.use('fivethirtyeight')
In [5]:
slices = [ 120, 70 ]
labels = ['Android', 'ios']
In [6]:
#plotting pie chart
plt.pie(slices, labels=labels)
plt.title("My Awesome Pie Chart")
plt.tight_layout()
plt.show()
In [7]:
#adding margin
plt.pie(slices, labels=labels, wedgeprops={'edgecolor':'black'})
plt.title("My Awesome Pie Chart")
plt.tight_layout()
plt.show()
In [10]:
slices = [ 120, 70, 30, 20 ]
labels = [ 'icecream', 'chocolate', 'pizza', 'burger' ]
colors = [ '#008fd5', '#fc4f30', '#e5ae37', '#6d904f' ]
#colors hexcode
# blue = #008fd5
# red = #fc4f30
# yellow = #e5ae37
# green = #6d904f
In [11]:
plt.pie(slices, labels=labels, wedgeprops={'edgecolor':'black'}, colors=colors)
plt.title("My Awesome Pie Chart")
plt.tight_layout()
plt.show()
In [12]:
# Language Popularity
slices = [59219, 55466, 47544, 36443, 35917, 31991, 27097, 23030, 20524, 18523, 18017, 7920, 7331, 7201, 5833]
labels = ['JavaScript', 'HTML/CSS', 'SQL', 'Python', 'Java', 'Bash/Shell/PowerShell', 'C#', 'PHP', 'C++', 'TypeScript', 'C', 'Other(s):', 'Ruby', 'Go', 'Assembly']
In [14]:
plt.pie(slices, labels=labels, wedgeprops={'edgecolor':'black'})
plt.title("My Awesome Pie Chart")
plt.tight_layout()
plt.show()
In [24]:
# Emphasis on particular label using explode
slices = [59219, 55466, 47544, 36443, 35917]
labels = ['JavaScript', 'HTML/CSS', 'SQL', 'Python', 'Java']
explode= [ 0, 0, 0, 0.1, 0]
In [28]:
#passing explode to pie chart, setting shadow, starting angle, adding percentage
plt.pie(slices, labels=labels, wedgeprops={'edgecolor':'black'},
        explode=explode,shadow=True, startangle=90, autopct='%1.1f%%')

plt.title("My Awesome Pie Chart")
plt.tight_layout()
plt.show()