Python Matplotlib - 3. Pie Charts

Table of Contents

  1. Run Code 1 in Python
  2. Output
  3. Run Code 2 in Python
  4. Output

Run Code 1 in Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
from matplotlib import pyplot as plt

plt.style.use("fivethirtyeight")


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

# Colors:
# Blue = #008fd5
# Red = #fc4f30
# Yellow = #e5ae37
# Green = #6d904f

starting_code.py

Output

Run Code 2 in Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from matplotlib import pyplot as plt

plt.style.use("fivethirtyeight")

slices = [59219, 55466, 47544, 36443, 35917]
labels = ['JavaScript', 'HTML/CSS', 'SQL', 'Python', 'Java']
explode = [0, 0, 0, 0.1, 0]

plt.pie(slices, labels=labels, explode=explode, shadow=True,
        startangle=90, autopct='%1.1f%%',
        wedgeprops={'edgecolor': 'black'})

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

finished_code.py

Output