编辑器 Pycharm 版本2017.2.1
爬取网址 http://www.weather.com.cn/textFC/shandong.shtml
将网址七天内的所有信息进行可视化
代码还有改进空间
#导入所需要的库
import requests
import re
import matplotlib.pyplot as plt
from bs4 import BeautifulSoup
from pyecharts.charts import Bar,Map,Parallel,Line
from pyecharts import options as opts
ALL_DATA=[] #创建全局变量 列表
ALL_SDDATA = []
#模拟浏览器爬取网页数据的函数
def parse_page(url):
response=requests.get(url) #requests 模拟浏览器发送请求
text = response.content.decode(‘utf-8’) #将模拟浏览返回数据转换格式
soup = BeautifulSoup(text, ‘html5lib’) #使用html5lib是因为网页返回的乱码问题
tables = soup.find_all(‘table’) #从返回的数据中寻找需要的数据 逻辑部分
listval=[0,17,34,51,68,85,102] #分析知道由于网页源码格式不利于爬取所以删去
for val in listval:
tables.remove(tables[val])
for table in tables: #下面都是用逻辑提取所需要的数据
trs=table.find_all(‘tr’)
tws=table.find_all(‘tr’)[0]
twds = tws.find_all(‘td’)
sdcities = twds[1]
sdcity = list(sdcities.stripped_strings)[0]
sdtemp_td = twds[-2]
sdmin_temp = list(sdtemp_td.stripped_strings)[0]
sdmtemp_td = twds[4]
sdmax_temp = list(sdmtemp_td.stripped_strings)[0]
ALL_SDDATA.append({‘sdcity’:sdcity,‘sdmin_temp’:sdmin_temp,‘sdmax_temp’:sdmax_temp})
for index,tr in enumerate(trs):
tds = tr.find_all(‘td’)
city_td = tds[0]
if(index==0):
city_td=tds[1]
city=list(city_td.stripped_strings)[0]
temp_td=tds[-2]
min_temp=list(temp_td.stripped_strings)[0]
mtemp_td = tds[-5]
max_temp = list(mtemp_td.stripped_strings)[0]
weather_td=tds[-4]
weather=list(weather_td.stripped_strings)[0]
weathern_td=tds[-7]
weatherday = list(weathern_td.stripped_strings)[0]
windn_td=tds[-3]
windn=list(windn_td.stripped_strings)[0]
wind_pow=list(windn_td.stripped_strings)[1]
string = wind_pow
windn_pow=min(re.findall(r"\d+.?\d*",string)) #数据清洗
wind_td = tds[-6]
windday_pow = list(wind_td.stripped_strings)[1]
windd = list(wind_td.stripped_strings)[0]
string1 = windday_pow
windd_pow = min(re.findall(r"\d+.?\d*", string1)) #数据清洗
ALL_DATA.append({“city”:city,‘weatherday’:weatherday,‘min_temp’:int(min_temp),‘max_temp’:max_temp,‘weather’:weather,‘windd_dir’:windd,‘windn_dir’:windn,‘windn_pow’:int(windn_pow),‘windd_pow’:int(windd_pow)}) #这里将所要爬取的数据放到列表中 列表对象以键值对方式存储
# print(ALL_DATA)
# print({“city”:city,“min_temp”:int(min_temp),“max_temp”:max_temp,“weather”:weather})
def main(): #main函数
url=‘http://www.weather.com.cn/textFC/shandong.shtml’
parse_page(url)
creat_AllNWeaPie()
creat_AllDWeaPie()
creat_MonNWeaPie()
creat_MonDWeaPie()
creat_TueNWeaPie()
creat_TueDWeaPie()
creat_WedNWeaPie()
creat_WedDWeaPie()
creat_ThuNWeaPie()
creat_ThuDWeaPie()
creat_FriNWeaPie()
creat_FriDWeaPie()
creat_SatNWeaPie()
creat_SatDWeaPie()
creat_SunNWeaPie()
creat_SunDWeaPie()
creat_AllDayWindPie()
creat_AllNigWindPie()
creat_MonDayWindPie()
creat_MonNigWindPie()
creat_TueDayWindPie()
creat_TueNigWindPie()
creat_WedDayWindPie()
creat_WedNigWindPie()
creat_ThuDayWindPie()
creat_ThuNigWindPie()
creat_FriDayWindPie()
creat_FriNigWindPie()
creat_SatDayWindPie()
creat_SatNigWindPie()
creat_SunDayWindPie()
creat_SunNigWindPie()
#风力状况 汇总 + 周一→周日
creat_AllDayWindPowPie()
creat_AllWindNigPowPie()
creat_MonDayWindPowPie()
creat_MonWindNigPowPie()
creat_TueDayWindPowPie()
creat_TueWindNigPowPie()
creat_WedDayWindPowPie()
creat_WedWindNigPowPie()
creat_ThuDayWindPowPie()
creat_ThuWindNigPowPie()
creat_FriDayWindPowPie()
creat_FriWindNigPowPie()
creat_SatDayWindPowPie()
creat_SatWindNigPowPie()
creat_SunDayWindPowPie()
creat_SunWindNigPowPie()
creat_Tempbar()
create_Map()
creat_plt()
#天气状况夜间
def creat_AllNWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[0:]
weas=list(map(lambda x:x['weather'],data0)) #利用lambda方法取出字典中key为'weather'的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea=="多云":
cloud += 1
lables.append('cloud')
elif wea=="晴":
sun += 1
lables.append('sun')
elif wea=="阴":
lables.append('cloudy')
cloudy+=1
elif wea=="小雨":
lables.append('lrain')
lrain+=1
elif wea=="中雨":
lables.append('mrain')
mrain+= 1
elif wea=="雷阵雨":
lables.append('zrain')
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1
plt.title("WeekWeaAtNig")
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title="WeaConition") #设置标签
plt.show()
def creat_MonNWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[0:156]
print(data0)
weas=list(map(lambda x:x[‘weather’],data0)) #利用lambda方法取出字典中key为’weather’的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea==“多云”:
cloud += 1
lables.append(‘cloud’)
elif wea==“晴”:
sun += 1
lables.append(‘sun’)
elif wea==“阴”:
lables.append(‘cloudy’)
cloudy+=1
elif wea==“小雨”:
lables.append(‘lrain’)
lrain+=1
elif wea==“中雨”:
lables.append(‘mrain’)
mrain+= 1
elif wea==“雷阵雨”:
lables.append(‘zrain’)
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1
plt.title(“WeekWeaAtNigMon”)
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WeaConition”) #设置标签
plt.show()
def creat_TueNWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[156:312]
weas=list(map(lambda x:x[‘weather’],data0)) #利用lambda方法取出字典中key为’weather’的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea==“多云”:
cloud += 1
lables.append(‘cloud’)
elif wea==“晴”:
sun += 1
lables.append(‘sun’)
elif wea==“阴”:
lables.append(‘cloudy’)
cloudy+=1
elif wea==“小雨”:
lables.append(‘lrain’)
lrain+=1
elif wea==“中雨”:
lables.append(‘mrain’)
mrain+= 1
elif wea==“雷阵雨”:
lables.append(‘zrain’)
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1 #
plt.title(“WeekWeaAtNigTue”)
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WeaConition”) #设置标签
plt.show()
def creat_WedNWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[312:468]
weas=list(map(lambda x:x[‘weather’],data0)) #利用lambda方法取出字典中key为’weather’的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea==“多云”:
cloud += 1
lables.append(‘cloud’)
elif wea==“晴”:
sun += 1
lables.append(‘sun’)
elif wea==“阴”:
lables.append(‘cloudy’)
cloudy+=1
elif wea==“小雨”:
lables.append(‘lrain’)
lrain+=1
elif wea==“中雨”:
lables.append(‘mrain’)
mrain+= 1
elif wea==“雷阵雨”:
lables.append(‘zrain’)
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1 #
plt.title(“WeekWeaAtNigWed”)
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WeaConition”) #设置标签
plt.show()
def creat_ThuNWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[468:624]
weas=list(map(lambda x:x[‘weather’],data0)) #利用lambda方法取出字典中key为’weather’的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea==“多云”:
cloud += 1
lables.append(‘cloud’)
elif wea==“晴”:
sun += 1
lables.append(‘sun’)
elif wea==“阴”:
lables.append(‘cloudy’)
cloudy+=1
elif wea==“小雨”:
lables.append(‘lrain’)
lrain+=1
elif wea==“中雨”:
lables.append(‘mrain’)
mrain+= 1
elif wea==“雷阵雨”:
lables.append(‘zrain’)
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1 #
plt.title(“WeekWeaAtNigThu”)
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WeaConition”) #设置标签
plt.show()
def creat_FriNWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[624:780]
weas=list(map(lambda x:x[‘weather’],data0)) #利用lambda方法取出字典中key为’weather’的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea==“多云”:
cloud += 1
lables.append(‘cloud’)
elif wea==“晴”:
sun += 1
lables.append(‘sun’)
elif wea==“阴”:
lables.append(‘cloudy’)
cloudy+=1
elif wea==“小雨”:
lables.append(‘lrain’)
lrain+=1
elif wea==“中雨”:
lables.append(‘mrain’)
mrain+= 1
elif wea==“雷阵雨”:
lables.append(‘zrain’)
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1 #
plt.title(“WeekWeaAtNigFri”)
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WeaConition”) #设置标签
plt.show()
def creat_SatNWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[780:936]
weas=list(map(lambda x:x[‘weather’],data0)) #利用lambda方法取出字典中key为’weather’的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea==“多云”:
cloud += 1
lables.append(‘cloud’)
elif wea==“晴”:
sun += 1
lables.append(‘sun’)
elif wea==“阴”:
lables.append(‘cloudy’)
cloudy+=1
elif wea==“小雨”:
lables.append(‘lrain’)
lrain+=1
elif wea==“中雨”:
lables.append(‘mrain’)
mrain+= 1
elif wea==“雷阵雨”:
lables.append(‘zrain’)
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1 #
plt.title(“WeekWeaAtNigSat”)
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WeaConition”) #设置标签
plt.show()
def creat_SunNWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[936:1092]
weas=list(map(lambda x:x[‘weather’],data0)) #利用lambda方法取出字典中key为’weather’的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea==“多云”:
cloud += 1
lables.append(‘cloud’)
elif wea==“晴”:
sun += 1
lables.append(‘sun’)
elif wea==“阴”:
lables.append(‘cloudy’)
cloudy+=1
elif wea==“小雨”:
lables.append(‘lrain’)
lrain+=1
elif wea==“中雨”:
lables.append(‘mrain’)
mrain+= 1
elif wea==“雷阵雨”:
lables.append(‘zrain’)
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0.1] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1 #
plt.title(“WeekWeaAtNigSun”)
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WeaConition”) #设置标签
plt.show()
#天气状况昼间
def creat_AllDWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[0:]
weas=list(map(lambda x:x['weatherday'],data0))
print(weas)
#利用lambda方法取出字典中key为'weather'的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea=="多云":
cloud += 1
lables.append('cloud')
elif wea=="晴":
sun += 1
lables.append('sun')
elif wea=="阴":
lables.append('cloudy')
cloudy+=1
elif wea=="小雨":
lables.append('lrain')
lrain+=1
elif wea=="中雨":
lables.append('mrain')
mrain+= 1
elif wea=="雷阵雨":
lables.append('zrain')
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1
plt.title("WeekWeaAtDay")
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title="WeaConition") #设置标签
plt.show()
def creat_MonDWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[0:156]
print(data0)
weas=list(map(lambda x:x[‘weatherday’],data0)) #利用lambda方法取出字典中key为’weather’的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea==“多云”:
cloud += 1
lables.append(‘cloud’)
elif wea==“晴”:
sun += 1
lables.append(‘sun’)
elif wea==“阴”:
lables.append(‘cloudy’)
cloudy+=1
elif wea==“小雨”:
lables.append(‘lrain’)
lrain+=1
elif wea==“中雨”:
lables.append(‘mrain’)
mrain+= 1
elif wea==“雷阵雨”:
lables.append(‘zrain’)
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1#
plt.title(“WeekWeaAtDayMon”)
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WeaConition”) #设置标签
plt.show()
def creat_TueDWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[156:312]
weas=list(map(lambda x:x[‘weatherday’],data0)) #利用lambda方法取出字典中key为’weather’的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea==“多云”:
cloud += 1
lables.append(‘cloud’)
elif wea==“晴”:
sun += 1
lables.append(‘sun’)
elif wea==“阴”:
lables.append(‘cloudy’)
cloudy+=1
elif wea==“小雨”:
lables.append(‘lrain’)
lrain+=1
elif wea==“中雨”:
lables.append(‘mrain’)
mrain+= 1
elif wea==“雷阵雨”:
lables.append(‘zrain’)
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1 #
plt.title(“WeekWeaAtTue”)
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WeaConition”) #设置标签
plt.show()
def creat_WedDWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[312:468]
weas=list(map(lambda x:x[‘weatherday’],data0)) #利用lambda方法取出字典中key为’weather’的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea==“多云”:
cloud += 1
lables.append(‘cloud’)
elif wea==“晴”:
sun += 1
lables.append(‘sun’)
elif wea==“阴”:
lables.append(‘cloudy’)
cloudy+=1
elif wea==“小雨”:
lables.append(‘lrain’)
lrain+=1
elif wea==“中雨”:
lables.append(‘mrain’)
mrain+= 1
elif wea==“雷阵雨”:
lables.append(‘zrain’)
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1 #
plt.title(“WeekWeaAtDayWed”)
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WeaConition”) #设置标签
plt.show()
def creat_ThuDWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[468:624]
weas=list(map(lambda x:x[‘weatherday’],data0)) #利用lambda方法取出字典中key为’weather’的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea==“多云”:
cloud += 1
lables.append(‘cloud’)
elif wea==“晴”:
sun += 1
lables.append(‘sun’)
elif wea==“阴”:
lables.append(‘cloudy’)
cloudy+=1
elif wea==“小雨”:
lables.append(‘lrain’)
lrain+=1
elif wea==“中雨”:
lables.append(‘mrain’)
mrain+= 1
elif wea==“雷阵雨”:
lables.append(‘zrain’)
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1
plt.title(“WeekWeaAtDayThu”)
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WeaConition”) #设置标签
plt.show()
def creat_FriDWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[624:780]
weas=list(map(lambda x:x[‘weatherday’],data0)) #利用lambda方法取出字典中key为’weather’的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea==“多云”:
cloud += 1
lables.append(‘cloud’)
elif wea==“晴”:
sun += 1
lables.append(‘sun’)
elif wea==“阴”:
lables.append(‘cloudy’)
cloudy+=1
elif wea==“小雨”:
lables.append(‘lrain’)
lrain+=1
elif wea==“中雨”:
lables.append(‘mrain’)
mrain+= 1
elif wea==“雷阵雨”:
lables.append(‘zrain’)
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1 #
plt.title(“WeekWeaAtDayFri”)
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WeaConition”) #设置标签
plt.show()
def creat_SatDWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[780:936]
weas=list(map(lambda x:x[‘weatherday’],data0)) #利用lambda方法取出字典中key为’weather’的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea==“多云”:
cloud += 1
lables.append(‘cloud’)
elif wea==“晴”:
sun += 1
lables.append(‘sun’)
elif wea==“阴”:
lables.append(‘cloudy’)
cloudy+=1
elif wea==“小雨”:
lables.append(‘lrain’)
lrain+=1
elif wea==“中雨”:
lables.append(‘mrain’)
mrain+= 1
elif wea==“雷阵雨”:
lables.append(‘zrain’)
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1 #
plt.title(“WeekWeaAtDaySat”)
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WeaConition”) #设置标签
plt.show()
def creat_SunDWeaPie(): #创建天气饼图
WEA_DATA=[]
cloud=0 #创建变量存储所得到的数据 依次是 多云 晴 阴 小雨 中雨 大雨 阵雨 还可以添加新的天气变量 这里我觉得这些天气变量已经足够了
sun=0
cloudy=0
lrain=0
mrain=0
zrain=0
lables =[]
data0 = ALL_DATA[936:1092]
weas=list(map(lambda x:x[‘weatherday’],data0)) #利用lambda方法取出字典中key为’weather’的value值并存储与列表weas中
wea_list = []
for wea in weas:
if wea==“多云”:
cloud += 1
lables.append(‘cloud’)
elif wea==“晴”:
sun += 1
lables.append(‘sun’)
elif wea==“阴”:
lables.append(‘cloudy’)
cloudy+=1
elif wea==“小雨”:
lables.append(‘lrain’)
lrain+=1
elif wea==“中雨”:
lables.append(‘mrain’)
mrain+= 1
elif wea==“雷阵雨”:
lables.append(‘zrain’)
zrain+=1
WEA=[cloud,sun,cloudy,lrain,mrain,zrain] #存取各天气数数量
for i in WEA: #for 循环剔除值为0的数据
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables: #for循环剔除lables中的相同数据并存放到LAB中
if not i in LAB:
LAB.append(i)
exp = [0,0.1] #添加逻辑使的饼图中第二比例可突出显示
value = len(LAB) #
wvalue=value-2 #
while(wvalue>0): #
exp.append(0) #
wvalue-=1 #
plt.title(“WeekWeaAtDaySun”)
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%") #利用matplotlib库的函数画图
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WeaConition”) #设置标签
plt.show()
#白天风向
def creat_AllDayWindPie(): #创建昼间风力饼图
WEA_DATA=[]
n=0 #创建变量代表八个方位的风向信息
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lables =[]
data1=ALL_DATA[0:]
weas=list(map(lambda x:x[‘windd_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lables.append(‘North’)
elif wea==“南风”:
s += 1
lables.append(‘South’)
elif wea==“东风”:
lables.append(‘East’)
e+=1
elif wea==“西风”:
lables.append(‘West’)
w+=1
elif wea==“东南风”:
lables.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lables.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lables.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lables.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“AllDayWindPie”)
plt.show()
def creat_MonDayWindPie(): #创建昼间风力饼图
WEA_DATA=[]
n=0 #创建变量代表八个方位的风向信息
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lables =[]
data1=ALL_DATA[0:156]
weas=list(map(lambda x:x[‘windd_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lables.append(‘North’)
elif wea==“南风”:
s += 1
lables.append(‘South’)
elif wea==“东风”:
lables.append(‘East’)
e+=1
elif wea==“西风”:
lables.append(‘West’)
w+=1
elif wea==“东南风”:
lables.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lables.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lables.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lables.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“MonDayWindPie”)
plt.show()
def creat_TueDayWindPie(): #创建昼间风力饼图
WEA_DATA=[]
n=0 #创建变量代表八个方位的风向信息
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lables =[]
data1=ALL_DATA[156:312]
weas=list(map(lambda x:x[‘windd_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lables.append(‘North’)
elif wea==“南风”:
s += 1
lables.append(‘South’)
elif wea==“东风”:
lables.append(‘East’)
e+=1
elif wea==“西风”:
lables.append(‘West’)
w+=1
elif wea==“东南风”:
lables.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lables.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lables.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lables.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“TueDayWindPie”)
plt.show()
def creat_WedDayWindPie(): #创建昼间风力饼图
WEA_DATA=[]
n=0 #创建变量代表八个方位的风向信息
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lables =[]
data1=ALL_DATA[312:468]
weas=list(map(lambda x:x[‘windd_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lables.append(‘North’)
elif wea==“南风”:
s += 1
lables.append(‘South’)
elif wea==“东风”:
lables.append(‘East’)
e+=1
elif wea==“西风”:
lables.append(‘West’)
w+=1
elif wea==“东南风”:
lables.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lables.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lables.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lables.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“WedDayWindPie”)
plt.show()
def creat_ThuDayWindPie(): #创建昼间风力饼图
WEA_DATA=[]
n=0 #创建变量代表八个方位的风向信息
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lables =[]
data1=ALL_DATA[468:624]
weas=list(map(lambda x:x[‘windd_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lables.append(‘North’)
elif wea==“南风”:
s += 1
lables.append(‘South’)
elif wea==“东风”:
lables.append(‘East’)
e+=1
elif wea==“西风”:
lables.append(‘West’)
w+=1
elif wea==“东南风”:
lables.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lables.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lables.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lables.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“ThuDayWindPie”)
plt.show()
def creat_FriDayWindPie(): #创建昼间风力饼图
WEA_DATA=[]
n=0 #创建变量代表八个方位的风向信息
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lables =[]
data1=ALL_DATA[624:780]
weas=list(map(lambda x:x[‘windd_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lables.append(‘North’)
elif wea==“南风”:
s += 1
lables.append(‘South’)
elif wea==“东风”:
lables.append(‘East’)
e+=1
elif wea==“西风”:
lables.append(‘West’)
w+=1
elif wea==“东南风”:
lables.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lables.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lables.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lables.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“FriDayWindPie”)
plt.show()
def creat_SatDayWindPie(): #创建昼间风力饼图
WEA_DATA=[]
n=0 #创建变量代表八个方位的风向信息
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lables =[]
data1=ALL_DATA[780:936]
weas=list(map(lambda x:x[‘windd_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lables.append(‘North’)
elif wea==“南风”:
s += 1
lables.append(‘South’)
elif wea==“东风”:
lables.append(‘East’)
e+=1
elif wea==“西风”:
lables.append(‘West’)
w+=1
elif wea==“东南风”:
lables.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lables.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lables.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lables.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“SatDayWindPie”)
plt.show()
def creat_SunDayWindPie(): #创建昼间风力饼图
WEA_DATA=[]
n=0 #创建变量代表八个方位的风向信息
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lables =[]
data1=ALL_DATA[936:1092]
weas=list(map(lambda x:x[‘windd_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lables.append(‘North’)
elif wea==“南风”:
s += 1
lables.append(‘South’)
elif wea==“东风”:
lables.append(‘East’)
e+=1
elif wea==“西风”:
lables.append(‘West’)
w+=1
elif wea==“东南风”:
lables.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lables.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lables.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lables.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“SunDayWindPie”)
plt.show()
#夜晚风向
def creat_AllNigWindPie(): #创建夜间风力饼图 这里可以做个分析对比夜间昼间风向和风力变化 得出结论
WEA_DATA=[]
n=0
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lable =[]
data1=ALL_DATA[0:]
weas=list(map(lambda x:x[‘windn_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lable.append(‘North’)
elif wea==“南风”:
s += 1
lable.append(‘South’)
elif wea==“东风”:
lable.append(‘East’)
e+=1
elif wea==“西风”:
lable.append(‘West’)
w+=1
elif wea==“东南风”:
lable.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lable.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lable.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lable.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lable:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“WindDirectionAtNight”)
plt.show()
def creat_MonNigWindPie(): #创建夜间风力饼图 这里可以做个分析对比夜间昼间风向和风力变化 得出结论
WEA_DATA=[]
n=0
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lable =[]
data1=ALL_DATA[0:156]
weas=list(map(lambda x:x[‘windn_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lable.append(‘North’)
elif wea==“南风”:
s += 1
lable.append(‘South’)
elif wea==“东风”:
lable.append(‘East’)
e+=1
elif wea==“西风”:
lable.append(‘West’)
w+=1
elif wea==“东南风”:
lable.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lable.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lable.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lable.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lable:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“MonNigWindPie”)
plt.show()
def creat_TueNigWindPie(): #创建夜间风力饼图 这里可以做个分析对比夜间昼间风向和风力变化 得出结论
WEA_DATA=[]
n=0
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lable =[]
data1=ALL_DATA[156:312]
weas=list(map(lambda x:x[‘windn_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lable.append(‘North’)
elif wea==“南风”:
s += 1
lable.append(‘South’)
elif wea==“东风”:
lable.append(‘East’)
e+=1
elif wea==“西风”:
lable.append(‘West’)
w+=1
elif wea==“东南风”:
lable.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lable.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lable.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lable.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lable:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“TueNigWindPie”)
plt.show()
def creat_WedNigWindPie(): #创建夜间风力饼图 这里可以做个分析对比夜间昼间风向和风力变化 得出结论
WEA_DATA=[]
n=0
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lable =[]
data1=ALL_DATA[312:468]
weas=list(map(lambda x:x[‘windn_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lable.append(‘North’)
elif wea==“南风”:
s += 1
lable.append(‘South’)
elif wea==“东风”:
lable.append(‘East’)
e+=1
elif wea==“西风”:
lable.append(‘West’)
w+=1
elif wea==“东南风”:
lable.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lable.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lable.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lable.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lable:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“WedNigWindPie”)
plt.show()
def creat_ThuNigWindPie(): #创建夜间风力饼图 这里可以做个分析对比夜间昼间风向和风力变化 得出结论
WEA_DATA=[]
n=0
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lable =[]
data1=ALL_DATA[468:624]
weas=list(map(lambda x:x[‘windn_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lable.append(‘North’)
elif wea==“南风”:
s += 1
lable.append(‘South’)
elif wea==“东风”:
lable.append(‘East’)
e+=1
elif wea==“西风”:
lable.append(‘West’)
w+=1
elif wea==“东南风”:
lable.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lable.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lable.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lable.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lable:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“ThuNigWindPie”)
plt.show()
def creat_FriNigWindPie(): #创建夜间风力饼图 这里可以做个分析对比夜间昼间风向和风力变化 得出结论
WEA_DATA=[]
n=0
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lable =[]
data1=ALL_DATA[624:780]
weas=list(map(lambda x:x[‘windn_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lable.append(‘North’)
elif wea==“南风”:
s += 1
lable.append(‘South’)
elif wea==“东风”:
lable.append(‘East’)
e+=1
elif wea==“西风”:
lable.append(‘West’)
w+=1
elif wea==“东南风”:
lable.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lable.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lable.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lable.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lable:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“FriNigWindPie”)
plt.show()
def creat_SatNigWindPie(): #创建夜间风力饼图 这里可以做个分析对比夜间昼间风向和风力变化 得出结论
WEA_DATA=[]
n=0
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lable =[]
data1=ALL_DATA[780:936]
weas=list(map(lambda x:x[‘windn_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lable.append(‘North’)
elif wea==“南风”:
s += 1
lable.append(‘South’)
elif wea==“东风”:
lable.append(‘East’)
e+=1
elif wea==“西风”:
lable.append(‘West’)
w+=1
elif wea==“东南风”:
lable.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lable.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lable.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lable.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lable:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“SatNigWindPie”)
plt.show()
def creat_SunNigWindPie(): #创建夜间风力饼图 这里可以做个分析对比夜间昼间风向和风力变化 得出结论
WEA_DATA=[]
n=0
s=0
w=0
e=0
en=0
es=0
ws=0
wn=0
lable =[]
data1=ALL_DATA[936:1092]
weas=list(map(lambda x:x[‘windn_dir’],data1))
for wea in weas:
if wea==“北风”:
n += 1
lable.append(‘North’)
elif wea==“南风”:
s += 1
lable.append(‘South’)
elif wea==“东风”:
lable.append(‘East’)
e+=1
elif wea==“西风”:
lable.append(‘West’)
w+=1
elif wea==“东南风”:
lable.append(‘Southeast’)
es+= 1
elif wea==“东北风”:
lable.append(‘Northeast’)
en+=1
elif wea == “西南风”:
lable.append(‘Southwest’)
ws += 1
elif wea == “西北风”:
lable.append(‘Northwest’)
wn += 1
WEA=[n,s,e,w,es,en,ws,wn]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lable:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1.1, 0, 0, 1.1), title=“WindDirection”)
plt.title(“SunNigWindPie”)
plt.show()
#昼间风力
def creat_AllDayWindPowPie(): #昼间风力大小饼图
WEA_DATA=[]
three=0 #创建变量使之代表各级风力大小情况
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables =[]
data1=ALL_DATA[0:]
weas=list(map(lambda x:x[‘windd_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables.append(‘Three’)
elif wea4:
four += 1
lables.append(‘Four’)
elif wea5:
lables.append(‘Five’)
five+=1
elif wea6:
lables.append(‘Six’)
six+=1
elif wea7:
lables.append(‘Seven’)
seven+= 1
elif wea8:
lables.append(‘Eight’)
eight+=1
elif wea == 9:
lables.append(‘Nine’)
nine += 1
elif wea == 10:
lables.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
l=len(WEA_DATA)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“AllDayWindPowPie”)
plt.show()
def creat_MonDayWindPowPie(): #昼间风力大小饼图
WEA_DATA=[]
three=0 #创建变量使之代表各级风力大小情况
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables =[]
data1=ALL_DATA[0:156]
weas=list(map(lambda x:x[‘windd_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables.append(‘Three’)
elif wea4:
four += 1
lables.append(‘Four’)
elif wea5:
lables.append(‘Five’)
five+=1
elif wea6:
lables.append(‘Six’)
six+=1
elif wea7:
lables.append(‘Seven’)
seven+= 1
elif wea8:
lables.append(‘Eight’)
eight+=1
elif wea == 9:
lables.append(‘Nine’)
nine += 1
elif wea == 10:
lables.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
l=len(WEA_DATA)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“MonDayWindPowPie”)
plt.show()
def creat_TueDayWindPowPie(): #昼间风力大小饼图
WEA_DATA=[]
three=0 #创建变量使之代表各级风力大小情况
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables =[]
data1=ALL_DATA[156:312]
weas=list(map(lambda x:x[‘windd_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables.append(‘Three’)
elif wea4:
four += 1
lables.append(‘Four’)
elif wea5:
lables.append(‘Five’)
five+=1
elif wea6:
lables.append(‘Six’)
six+=1
elif wea7:
lables.append(‘Seven’)
seven+= 1
elif wea8:
lables.append(‘Eight’)
eight+=1
elif wea == 9:
lables.append(‘Nine’)
nine += 1
elif wea == 10:
lables.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
l=len(WEA_DATA)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“TueDayWindPowPie”)
plt.show()
def creat_WedDayWindPowPie(): #昼间风力大小饼图
WEA_DATA=[]
three=0 #创建变量使之代表各级风力大小情况
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables =[]
data1=ALL_DATA[312:468]
weas=list(map(lambda x:x[‘windd_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables.append(‘Three’)
elif wea4:
four += 1
lables.append(‘Four’)
elif wea5:
lables.append(‘Five’)
five+=1
elif wea6:
lables.append(‘Six’)
six+=1
elif wea7:
lables.append(‘Seven’)
seven+= 1
elif wea8:
lables.append(‘Eight’)
eight+=1
elif wea == 9:
lables.append(‘Nine’)
nine += 1
elif wea == 10:
lables.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
l=len(WEA_DATA)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“WedDayWindPowPie”)
plt.show()
def creat_ThuDayWindPowPie(): #昼间风力大小饼图
WEA_DATA=[]
three=0 #创建变量使之代表各级风力大小情况
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables =[]
data1=ALL_DATA[468:624]
weas=list(map(lambda x:x[‘windd_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables.append(‘Three’)
elif wea4:
four += 1
lables.append(‘Four’)
elif wea5:
lables.append(‘Five’)
five+=1
elif wea6:
lables.append(‘Six’)
six+=1
elif wea7:
lables.append(‘Seven’)
seven+= 1
elif wea8:
lables.append(‘Eight’)
eight+=1
elif wea == 9:
lables.append(‘Nine’)
nine += 1
elif wea == 10:
lables.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
l=len(WEA_DATA)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“ThuDayWindPowPie”)
plt.show()
def creat_FriDayWindPowPie(): #昼间风力大小饼图
WEA_DATA=[]
three=0 #创建变量使之代表各级风力大小情况
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables =[]
data1=ALL_DATA[624:780]
weas=list(map(lambda x:x[‘windd_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables.append(‘Three’)
elif wea4:
four += 1
lables.append(‘Four’)
elif wea5:
lables.append(‘Five’)
five+=1
elif wea6:
lables.append(‘Six’)
six+=1
elif wea7:
lables.append(‘Seven’)
seven+= 1
elif wea8:
lables.append(‘Eight’)
eight+=1
elif wea == 9:
lables.append(‘Nine’)
nine += 1
elif wea == 10:
lables.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
l=len(WEA_DATA)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“FriDayWindPowPie”)
plt.show()
def creat_SatDayWindPowPie(): #昼间风力大小饼图
WEA_DATA=[]
three=0 #创建变量使之代表各级风力大小情况
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables =[]
data1=ALL_DATA[780:936]
weas=list(map(lambda x:x[‘windd_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables.append(‘Three’)
elif wea4:
four += 1
lables.append(‘Four’)
elif wea5:
lables.append(‘Five’)
five+=1
elif wea6:
lables.append(‘Six’)
six+=1
elif wea7:
lables.append(‘Seven’)
seven+= 1
elif wea8:
lables.append(‘Eight’)
eight+=1
elif wea == 9:
lables.append(‘Nine’)
nine += 1
elif wea == 10:
lables.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
l=len(WEA_DATA)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“SatDayWindPowPie”)
plt.show()
def creat_SunDayWindPowPie(): #昼间风力大小饼图
WEA_DATA=[]
three=0 #创建变量使之代表各级风力大小情况
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables =[]
data1=ALL_DATA[936:1092]
weas=list(map(lambda x:x[‘windd_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables.append(‘Three’)
elif wea4:
four += 1
lables.append(‘Four’)
elif wea5:
lables.append(‘Five’)
five+=1
elif wea6:
lables.append(‘Six’)
six+=1
elif wea7:
lables.append(‘Seven’)
seven+= 1
elif wea8:
lables.append(‘Eight’)
eight+=1
elif wea == 9:
lables.append(‘Nine’)
nine += 1
elif wea == 10:
lables.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
l=len(WEA_DATA)
LAB = []
for i in lables:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“SunDayWindPowPie”)
plt.show()
#夜间风力
def creat_AllWindNigPowPie(): #夜间风力大小饼图
WEA_DATA=[]
three=0
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables1 =[]
data1=ALL_DATA[0:]
weas=list(map(lambda x:x[‘windn_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables1.append(‘Three’)
elif wea4:
four += 1
lables1.append(‘Four’)
elif wea5:
lables1.append(‘Five’)
five+=1
elif wea6:
lables1.append(‘Six’)
six+=1
elif wea7:
lables1.append(‘Seven’)
seven+= 1
elif wea8:
lables1.append(‘Eight’)
eight+=1
elif wea == 9:
lables1.append(‘Nine’)
nine += 1
elif wea == 10:
lables1.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables1:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“AllWindNigPowPie”)
plt.show()
def creat_MonWindNigPowPie(): #夜间风力大小饼图
WEA_DATA=[]
three=0
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables1 =[]
data1=ALL_DATA[0:156]
weas=list(map(lambda x:x[‘windn_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables1.append(‘Three’)
elif wea4:
four += 1
lables1.append(‘Four’)
elif wea5:
lables1.append(‘Five’)
five+=1
elif wea6:
lables1.append(‘Six’)
six+=1
elif wea7:
lables1.append(‘Seven’)
seven+= 1
elif wea8:
lables1.append(‘Eight’)
eight+=1
elif wea == 9:
lables1.append(‘Nine’)
nine += 1
elif wea == 10:
lables1.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables1:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“MonWindNigPowPie”)
plt.show()
def creat_TueWindNigPowPie(): #夜间风力大小饼图
WEA_DATA=[]
three=0
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables1 =[]
data1=ALL_DATA[156:312]
weas=list(map(lambda x:x[‘windn_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables1.append(‘Three’)
elif wea4:
four += 1
lables1.append(‘Four’)
elif wea5:
lables1.append(‘Five’)
five+=1
elif wea6:
lables1.append(‘Six’)
six+=1
elif wea7:
lables1.append(‘Seven’)
seven+= 1
elif wea8:
lables1.append(‘Eight’)
eight+=1
elif wea == 9:
lables1.append(‘Nine’)
nine += 1
elif wea == 10:
lables1.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables1:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“TueWindNigPowPie”)
plt.show()
def creat_WedWindNigPowPie(): #夜间风力大小饼图
WEA_DATA=[]
three=0
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables1 =[]
data1=ALL_DATA[312:468]
weas=list(map(lambda x:x[‘windn_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables1.append(‘Three’)
elif wea4:
four += 1
lables1.append(‘Four’)
elif wea5:
lables1.append(‘Five’)
five+=1
elif wea6:
lables1.append(‘Six’)
six+=1
elif wea7:
lables1.append(‘Seven’)
seven+= 1
elif wea8:
lables1.append(‘Eight’)
eight+=1
elif wea == 9:
lables1.append(‘Nine’)
nine += 1
elif wea == 10:
lables1.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables1:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“WedWindNigPowPie”)
plt.show()
def creat_ThuWindNigPowPie(): #夜间风力大小饼图
WEA_DATA=[]
three=0
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables1 =[]
data1=ALL_DATA[468:624]
weas=list(map(lambda x:x[‘windn_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables1.append(‘Three’)
elif wea4:
four += 1
lables1.append(‘Four’)
elif wea5:
lables1.append(‘Five’)
five+=1
elif wea6:
lables1.append(‘Six’)
six+=1
elif wea7:
lables1.append(‘Seven’)
seven+= 1
elif wea8:
lables1.append(‘Eight’)
eight+=1
elif wea == 9:
lables1.append(‘Nine’)
nine += 1
elif wea == 10:
lables1.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables1:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“ThuWindNigPowPie”)
plt.show()
def creat_FriWindNigPowPie(): #夜间风力大小饼图
WEA_DATA=[]
three=0
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables1 =[]
data1=ALL_DATA[624:780]
weas=list(map(lambda x:x[‘windn_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables1.append(‘Three’)
elif wea4:
four += 1
lables1.append(‘Four’)
elif wea5:
lables1.append(‘Five’)
five+=1
elif wea6:
lables1.append(‘Six’)
six+=1
elif wea7:
lables1.append(‘Seven’)
seven+= 1
elif wea8:
lables1.append(‘Eight’)
eight+=1
elif wea == 9:
lables1.append(‘Nine’)
nine += 1
elif wea == 10:
lables1.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables1:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“FriWindNigPowPie”)
plt.show()
def creat_SatWindNigPowPie(): #夜间风力大小饼图
WEA_DATA=[]
three=0
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables1 =[]
data1=ALL_DATA[780:936]
weas=list(map(lambda x:x[‘windn_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables1.append(‘Three’)
elif wea4:
four += 1
lables1.append(‘Four’)
elif wea5:
lables1.append(‘Five’)
five+=1
elif wea6:
lables1.append(‘Six’)
six+=1
elif wea7:
lables1.append(‘Seven’)
seven+= 1
elif wea8:
lables1.append(‘Eight’)
eight+=1
elif wea == 9:
lables1.append(‘Nine’)
nine += 1
elif wea == 10:
lables1.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables1:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“SatWindNigPowPie”)
plt.show()
def creat_SunWindNigPowPie(): #夜间风力大小饼图
WEA_DATA=[]
three=0
four=0
five=0
six=0
seven=0
eight=0
nine=0
ten=0
lables1 =[]
data1=ALL_DATA[936:1092]
weas=list(map(lambda x:x[‘windn_pow’],data1))
for wea in weas:
if wea3:
three += 1
lables1.append(‘Three’)
elif wea4:
four += 1
lables1.append(‘Four’)
elif wea5:
lables1.append(‘Five’)
five+=1
elif wea6:
lables1.append(‘Six’)
six+=1
elif wea7:
lables1.append(‘Seven’)
seven+= 1
elif wea8:
lables1.append(‘Eight’)
eight+=1
elif wea == 9:
lables1.append(‘Nine’)
nine += 1
elif wea == 10:
lables1.append(‘Ten’)
ten += 1
WEA=[three,four,five,six,seven,eight,nine,ten]
for i in WEA:
if i >= 1:
WEA_DATA.append(i)
LAB = []
for i in lables1:
if not i in LAB:
LAB.append(i)
exp = [0, 0.1,]
value = len(LAB)
wvalue=value-2
while(wvalue>0):
exp.append(0)
wvalue-=1
plt.pie(x=WEA_DATA,labels=LAB,explode=exp,shadow=True,autopct="%0.2f%%")
plt.legend(bbox_to_anchor=(1, 0, 0, 1), title=“WindPower”)
plt.title(“SunWindNigPowPie”)
plt.show()
def creat_Tempbar(): #柱状图 高低气温排行榜
data=ALL_DATA[0:156] #取出所需要的数据 因为ALL_DATA中是七天的数据所以截取某一天所有地区数据就可以
data1=ALL_DATA[0:156]
data.sort(key=lambda data: data[‘min_temp’])
data1.sort(key=lambda data: data[‘max_temp’])
cities1 = list(map(lambda x: x[‘city’], data))
cities1_1=cities1[0:10] #取出前十名
cities2 = list(map(lambda x: x[‘city’], data1))
cities2_1=cities2[0:10]
mintemps = list(map(lambda x: x[‘min_temp’], data))
mintemps_1=mintemps[0:10]
maxtemps = list(map(lambda x: x[‘max_temp’], data1))
maxtemps_1=maxtemps[0:10]
color_maxfunction = ‘red’
color_minfunction=‘blue’
maxtemps_1.reverse() #反转列表
chart1 = Bar()
chart2 = Bar()
chart1.add_xaxis(cities1_1)
chart2.add_xaxis(cities2_1) #这里的柱状图用的是pycharts库 这里是分别对两个图的x轴设置数据(前十五名城市名字) 下面是对y轴设置数据
chart1.add_yaxis(“城市”, mintemps_1,category_gap=“40%”,itemstyle_opts=opts.ItemStyleOpts(color=color_minfunction))
chart2.add_yaxis(“城市”, maxtemps_1,category_gap=“40%”,itemstyle_opts=opts.ItemStyleOpts(color=color_maxfunction))
chart1.set_global_opts(title_opts=opts.TitleOpts(title=“山东天气实时最低气温排行榜”))
chart2.set_global_opts(title_opts=opts.TitleOpts(title=“山东天气实时最高气温排行榜”))
chart1.render(‘SD_Mintemp.html’) #生成html网页显示图例
chart2.render(‘SD_Maxtemp.html’)
def creat_plt(): #主要城市气温折线图
data1=[]
dindex=[0,156,312,468,624,780,936]
# cities2=[]
# maxtemp=[]
# mintemp=[]
for i in dindex:
data1.append(ALL_DATA[i])
print(data1)
cities2=[“周四”,“周五”,“周六”,“周天”,“周一”,“周二”,“周三”,]
y_maxtemp=list(map(lambda x:x[‘max_temp’],data1))
maxtemp = y_maxtemp[0:7]
y_mintemp=list(map(lambda x:x[‘min_temp’],data1))
mintemp=y_mintemp[0:7]
c = Line()
c.set_global_opts(
# 设置标题
title_opts=opts.TitleOpts(title=“省会城市七天最高最低气温折线图”),
# 设置图例is_show=False是不显示图例
legend_opts=opts.LegendOpts(is_show=True),
)
c.add_xaxis(xaxis_data=cities2)
c.add_yaxis(series_name=’’, y_axis=mintemp)
c.add_yaxis(series_name=’’, y_axis=maxtemp)
c.render(‘Line-High-Low.html’)
def create_Map(): #山东省气温状态图
data = ALL_SDDATA[0:17]
mintemps = list(map(lambda x: x[‘sdmin_temp’], data))
maxtemps= list(map(lambda x: x[‘sdmax_temp’], data))
print(maxtemps)
print(mintemps)
a_city = [“济南市”,“青岛市”,“淄博市”,“德州市”,“烟台市”,“潍坊市”,“济宁市”,“泰安市”,“临沂市”,“菏泽市”,“滨州市”,“东营市”,“威海市”,“枣庄市”,“日照市”,“莱芜市”,“聊城市”]
m = Map()
w= Map()
m.add("", zip(a_city,mintemps), maptype=“山东”) #函数就这样用没什么好说的zip()的两个参数 maptype代表生成地区
w.add("", zip(a_city,maxtemps), maptype=“山东”)
m.set_global_opts(title_opts=opts.TitleOpts(title=“山东省最低气温状态图”, pos_left = ‘center’ ),visualmap_opts=opts.VisualMapOpts(min_=5,max_=15))
w.set_global_opts(title_opts=opts.TitleOpts(title=“山东省最高气温状态图”, pos_left = ‘center’ ),visualmap_opts=opts.VisualMapOpts(min_=15,max_=25)) #设置标题及显示衡量标准
m.render(“Map-low.html”)
w.render(“Map-High.html”) #状态图使用pycharts库实现
if name==‘main’:
main()