Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import csv
- import pandas as pd
- from matplotlib.font_manager import FontProperties
- import matplotlib.pyplot as plt
- plt.rcParams['font.sans-serif'] = ['Microsoft JhengHei']
- plt.rcParams['axes.unicode_minus'] = False
- filename='t187ap05_L.csv'
- industry_dic = {}
- revenue_dic = {}
- with open(filename,"r",encoding="utf-8") as file:
- # cols4 = sheet1.col_values(4)
- reader = csv.reader(file)
- header_col=next(reader)
- for col in reader:
- if col[4] in industry_dic.keys():
- industry_dic[col[4]] += 1
- else:
- industry_dic[col[4]] = 1
- if col[4] in revenue_dic.keys():
- revenue_dic[col[4]] += int(col[5])
- else:
- revenue_dic[col[4]] = 0
- #各產業公司數長條圖
- label = list(industry_dic.keys())
- quantity = list(industry_dic.values())
- index = list(range(len(label)))
- plt.figure(figsize=(10,10))
- plt.barh(label,quantity)
- plt.yticks(index,label)
- plt.xlabel('公司數')
- plt.title('各產業公司數')
- plt.show()
- #各產業當月營收圓餅圖
- label = list(revenue_dic.keys())
- revenue = list(revenue_dic.values())
- plt.figure(figsize=(15,15))
- plt.pie(revenue, labels = label, autopct = "%1.1f%%",
- textprops = {"fontsize" : 8},labeldistance = 1.02)
- plt.title('各產業當月營收百分比',fontsize = 10)
- plt.axis("off")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement