forked from ccccourse/sp110b
-
Notifications
You must be signed in to change notification settings - Fork 1
期中.md
mozi5269 edited this page Jun 17, 2022
·
6 revisions
import requests
import matplotlib.pyplot as plt
import re
import numpy as np
from bs4 import BeautifulSoup
url ='https://apex.tracker.gg/apex/insights'
r = requests.get(url)
sp = BeautifulSoup(r.text,'lxml')
datas = sp.find('div', class_='usage__content trn-grid trn-grid--vertical trn-grid--tiny')
names = datas.find_all('div',class_='insight-bar__label')
nums= datas.find_all('div',class_='insight-bar__value')
sizes=[]
use=[]
for i in range (0,19):
temp=nums[i].text
legends=names[i].text
print('Legend:',legends, end=' ')
print('Using:',temp)
use.append(re.search('\d+.\d+', temp).group())
sizes=list(np.float_(use))
plt.pie(sizes,startangle=90)
當初不應該用pie chart的,會顯得很壅擠,使用bar chart 應該會好很多,以及每個部份對應的文字,是我自己後製上去的,應該是有辦法一起顯示的。
《Python 初學特訓班》6、7章節內容和習題