# Importing pandas and matplotlib
import pandas as pd
from matplotlib import pyplot as plt
# Read excel
Mydata7 = pd.read_excel('D:\\DATA SCIENCE Learning 2021\\DATA VIZ Python Basic\\file7.xlsx')
Mydata7
# Creating simple Pie Chart
mycolors = ["#E3CF57", "#66CDAA", "#CD3333", "#6495ED","blue","green"]
# For color code, you can reference from https://planetnz.blogspot.com/2022/02/color-code-in-ascii.html
plt.pie(Mydata7[2021], labels = Mydata7['City Population'], colors=mycolors,
startangle=90, shadow = True, explode = (0, 0, 0.1, 0,0,0),
radius = 1.3, autopct = '%1.1f%%')
#add the labels
plt.title("City Population of 2021",fontsize = 18,pad = 14)
# plotting legend
plt.legend(bbox_to_anchor = (1.2, 1))
# showing the plot
plt.show()
Source data table :
City Population | 2019 | 2020 | 2021 |
Yangon | 300,000 | 312,000 | 350,000 |
Mandalay | 270,000 | 290,000 | 310,000 |
Sagaing | 160,000 | 170,000 | 190,000 |
MonYwar | 180,000 | 190,000 | 210,000 |
Harkhar | 90,000 | 100,000 | 110,000 |
Loikaw | 140,000 | 150,000 | 160,000 |
Reference Websites :
https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.pie.html?highlight=pie#matplotlib.axes.Axes.pie
https://www.w3schools.com/python/matplotlib_pie_charts.asp
No comments:
Post a Comment