佛山网站排名提升,如何制作ppt视频教程,wordpress 页面 自定义页面,网站建设收徒弟天气预报我们每天都会关注#xff0c;我们可以根据未来的天气增减衣物、安排出行#xff0c;每天的气温、风速风向、相对湿度、空气质量等成为关注的焦点。本次使用python中requests和BeautifulSoup库对中国天气网当天和未来14天的数据进行爬取#xff0c;保存为csv文件我们可以根据未来的天气增减衣物、安排出行每天的气温、风速风向、相对湿度、空气质量等成为关注的焦点。本次使用python中requests和BeautifulSoup库对中国天气网当天和未来14天的数据进行爬取保存为csv文件之后用matplotlib、numpy、pandas对数据进行可视化处理和分析得到温湿度度变化曲线、空气质量图、风向雷达图等结果为获得未来天气信息提供了有效方法。 1、数据获取
请求网站链接
首先查看中国天气网的网址http://www.weather.com.cn/weather/101280701.shtml这里就访问本地的天气网址如果想爬取不同的地区只需修改最后的101280701地区编号即可前面的weather代表是7天的网页weather1d代表当天weather15d代表未来14天。这里就主要访问7天和14天的中国天气网。采用requests.get()方法请求网页如果成功访问则得到的是网页的所有字符串文本。这就是请求过程。
def getHTMLtext(url): 请求获得网页内容try: r requests.get(url, timeout 30) r.raise_for_status() r.encoding r.apparent_encoding print(成功访问) return r.text except: print(访问错误) return 提取有用信息
这里采用BeautifulSoup库对刚刚获取的字符串进行数据提取首先对网页进行检查找到需要获取数据的标签 可以发现7天的数据信息在div标签中并且id“7d”并且日期、天气、温度、风级等信息都在ul和li标签中所以我们可以使用BeautifulSoup对获取的网页文本进行查找div标签id“7d”找出他包含的所有的ul和li标签之后提取标签中相应的数据值保存到对应列表中。
这里要注意一个细节就是有时日期没有最高气温对于没有数据的情况要进行判断和处理。另外对于一些数据保存的格式也要提前进行处理比如温度后面的摄氏度符号日期数字的提取和风级文字的提取这需要用到字符查找及字符串切片处理。
def get_content(html):
处理得到有用信息保存数据文件
final [] # 初始化一个列表保存数据
bs BeautifulSoup(html, html.parser) # 创建BeautifulSoup对象
body bs.body
data body.find(div, {id: 7d}) # 找到div标签且id 7d下面爬取当天的数据
data2 body.find_all(div,{class:left-div})
text data2[2].find(script).string
text text[text.index()1 :-2] # 移除改var data将其变为json数据
jd json.loads(text)
dayone jd[od][od2] # 找到当天的数据
final_day [] # 存放当天的数据
count 0
for i in dayone:
temp []
if count 23:
temp.append(i[od21]) # 添加时间
temp.append(i[od22]) # 添加当前时刻温度
temp.append(i[od24]) # 添加当前时刻风力方向
temp.append(i[od25]) # 添加当前时刻风级
temp.append(i[od26]) # 添加当前时刻降水量
temp.append(i[od27]) # 添加当前时刻相对湿度
temp.append(i[od28]) # 添加当前时刻控制质量
#print(temp)
final_day.append(temp)
count count 1下面爬取7天的数据
ul data.find(ul) # 找到所有的ul标签
li ul.find_all(li) # 找到左右的li标签
i 0 # 控制爬取的天数
for day in li: # 遍历找到的每一个li
if i 7 and i 0:
temp [] # 临时存放每天的数据
date day.find(h1).string # 得到日期
date date[0:date.index(日)] # 取出日期号
temp.append(date) inf day.find_all(p) # 找出li下面的p标签,提取第一个p标签的值即天气
temp.append(inf[0].string)tem_low inf[1].find(i).string # 找到最低气温if inf[1].find(span) is None: # 天气预报可能没有最高气温tem_high Noneelse:tem_high inf[1].find(span).string # 找到最高气温temp.append(tem_low[:-1])if tem_high[-1] ℃:temp.append(tem_high[:-1])else:temp.append(tem_high)wind inf[2].find_all(span) # 找到风向for j in wind:temp.append(j[title])wind_scale inf[2].find(i).string # 找到风级index1 wind_scale.index(级)temp.append(int(wind_scale[index1-1:index1]))final.append(temp)
i i 1return final_day,final同样对于/weather15d15天的信息也做同样的处理这里经过查看后发现他的15天网页中只有8-14天前面的1-7天在/weather中这里就分别访问两个网页将爬取得到的数据进行合并得到最终14天的数据。- 前面是未来14天的数据爬取过程对于当天24小时的天气信息数据经过查找发现他是一个json数据可以通过json.loads()
方法获取当天的数据进而对当天的天气信息进行提取。 保存csv文件
前面将爬取的数据添加到列表中这里引入csv库利用f_csv.writerow(header)和f_csv.writerows(data)方法分别写入表头和每一行的数据这里将1天和未来14天的数据分开存储分别保存为weather1.csv和weather14.csv下面是他们保存的表格图 2.可视化分析
当天温度变化曲线图
采用matplotlib中plt.plot()方法绘制出一天24小时的温度变化曲线并用plt.text()方法点出最高温和最低温并画出平均温度线下图为温度变化曲线图(代码见附录) 分析可以发现这一天最高温度为33℃最低温度为28℃并且平均温度在20.4℃左右通过对时间分析发现昼夜温差5℃低温分布在凌晨高温分布在中午到下午的时间段。
当天相对湿度变化曲线图
采用matplotlib中plt.plot()方法绘制出一天24小时的湿度变化曲线并画出平均相对湿度线下图为湿度变化曲线图(代码见附录) 分析可以发现这一天最高相对湿度为86%最低相对湿度为58℃并且平均相对湿度在75%左右通过对时间分析清晨的湿度比较大而下午至黄昏湿度较小。
温湿度相关性分析图
经过前面两个图的分析我们可以感觉到温度和湿度之间是有关系的为了更加清楚直观地感受这种关系使用plt.scatter()方法将温度为横坐标、湿度为纵坐标每个时刻的点在图中点出来并且计算相关系数下图为结果图 分析可以发现一天的温度和湿度具有强烈的相关性他们呈负相关这就说明他们时间是负相关关系并且进一步分析当温度较低时空气中水分含量较多湿度自然较高而温度较高时水分蒸发空气就比较干 燥湿度较低符合平时气候现象。
空气质量指数柱状图
空气质量指数AQI是定量描述空气质量状况的指数其数值越大说明空气污染状况越重对人体健康的危害也就越大。一般将空气质量指数分为6个等级等级越高说明污染越严重下面使用plt.bar方法对一天24小时的空气质量进行了柱状图绘制并且根据6个等级的不同相应的柱状图的颜色也从浅到深也表明污染逐步加重更直观的显示污染情况并且也将最高和最低的空气质量指数标出用虚线画出平均的空气质量指数下图是绘制结果图 上面这张是南方珠海的控制质量图可以看出空气质量指数最大也是在健康范围说明珠海空气非常好分析可以发现这一天最高空气质量指数达到了35最低则只有14并且平均在25左右通过时间也可以发现基本在清晨的时候是空气最好的时候4-9点在下午是空气污染最严重的时候所以清晨一般可以去外面呼吸新鲜的空气那时污染最小。
而下面这个空气质量图是选取的北方的一个城市可以看到这里的环境远远比不上珠海。 风向风级雷达图
统计一天的风力和风向由于风力风向使用极坐标的方式展现较好所以这里采用的是极坐标的方式展现一天的风力风向图将圆分为8份每一份代表一个风向半径代表平均风力并且随着风级增高蓝色加深最后结果如下所示 分析可以发现这一天西南风最多平均风级达到了1.75级东北风也有小部分1.0级其余空白方向无来风。
未来14天高低温变化曲线图
统计未来14天的高低温度变化并绘制出他们的变化曲线图分别用虚线将他们的平均气温线绘制出来最后结果如下所示 分析可以发现未来14天高温平均气温为30.5℃温度还是比较高但是未来的第8天有降温需要做好降温准备低温前面处于平稳趋势等到第8天开始下降伴随着高温也下降整体温度下降低温平均在27℃左右。
未来14天风向风级雷达图
统计未来14天的风向和平均风力并和前面一样采用极坐标形式将圆周分为8个部分代表8个方向颜色越深代表风级越高最后结果如下所示 分析可以发现未来14天东南风、西南风所占主要风向风级最高达到了5级最低的西风平均风级也有3级。
未来14天气候分布饼图
统计未来14天的气候并求每个气候的总天数最后将各个气候的饼图绘制出来结果如下所示 分析可以发现未来14天气候基本是“雨”、“阴转雨”和“阵雨”下雨的天数较多,结合前面的气温分布图可以看出在第8-9天气温高温下降可以推测当天下雨导致气温下降。
3、结论
1.首先根据爬取的温湿度数据进行的分析温度从早上低到中午高再到晚上低湿度和温度的趋势相反通过相关系数发现温度和湿度有强烈的负相关关系经查阅资料发现因为随着温度升高水蒸汽蒸发加剧空气中水分降低湿度降低。当然湿度同时受气压和雨水的影响下雨湿度会明显增高。
2.经查阅资料空气质量不仅跟工厂、汽车等排放的烟气、废气等有关更为重要的是与气象因素有关。由于昼夜温差明显变化当地面温度高于高空温度时空气上升污染物易被带到高空扩散当地面温度低于一定高度的温度时天空形成逆温层它像一个大盖子一样压在地面上空使地表空气中各种污染物不易扩散。一般在晚间和清晨影响较大而当太阳出来后地面迅速升温逆温层就会逐渐消散于是污染空气也就扩散了。
3.风是由气压在水平方向分布的不均匀导致的。风受大气环流、地形、水域等不同因素的综合影响表现形式多种多样如季风、地方性的海陆风、山谷风等一天的风向也有不同的变化根据未来14天的风向雷达图可以发现未来所有风向基本都有涉及并且没有特别的某个风向原因可能是近期没有降水和气文变化不大导致风向也没有太大的变化规律。
4.天气是指某一个地区距离地表较近的大气层在短时间内的具体状态。跟某瞬时内大气中各种气象要素分布的综合表现。根据未来14天的天气和温度变化可以大致推断出某个时间的气候天气和温度之间也是有联系的。
4、代码框架
代码主要分为weather.py对中国天气网进行爬取天气数据并保存csv文件data1_analysis.py对当天的天气信息进行可视化处理data14_analysis.py对未来14天的天气信息进行可视化处理。下面是代码的结构图 附源代码
weather.py
# weather.py
import requests
from bs4 import BeautifulSoup
import csv
import json
def getHTMLtext(url): 请求获得网页内容try: r requests.get(url, timeout 30) r.raise_for_status() r.encoding r.apparent_encoding print(成功访问) return r.text except: print(访问错误) return def get_content(html):处理得到有用信息保存数据文件final [] # 初始化一个列表保存数据bs BeautifulSoup(html, html.parser) # 创建BeautifulSoup对象body bs.bodydata body.find(div, {!-- --id: 7d}) # 找到div标签且id 7d# 下面爬取当天的数据data2 body.find_all(div,{!-- --class:left-div})text data2[2].find(script).string text text[text.index()1 :-2] # 移除改var data将其变为json数据jd json.loads(text)dayone jd[od][od2] # 找到当天的数据final_day [] # 存放当天的数据count 0for i in dayone:temp []if count lt;23:temp.append(i[od21]) # 添加时间temp.append(i[od22]) # 添加当前时刻温度temp.append(i[od24]) # 添加当前时刻风力方向temp.append(i[od25]) # 添加当前时刻风级temp.append(i[od26]) # 添加当前时刻降水量temp.append(i[od27]) # 添加当前时刻相对湿度temp.append(i[od28]) # 添加当前时刻控制质量#print(temp)final_day.append(temp)count count 1# 下面爬取7天的数据 ul data.find(ul) # 找到所有的ul标签li ul.find_all(li) # 找到左右的li标签i 0 # 控制爬取的天数for day in li: # 遍历找到的每一个liif i lt; 7 and i gt; 0:temp [] # 临时存放每天的数据date day.find(h1).string # 得到日期date date[0:date.index(日)] # 取出日期号temp.append(date) inf day.find_all(p) # 找出li下面的p标签,提取第一个p标签的值即天气temp.append(inf[0].string)tem_low inf[1].find(i).string # 找到最低气温if inf[1].find(span) is None: # 天气预报可能没有最高气温tem_high Noneelse:tem_high inf[1].find(span).string # 找到最高气温temp.append(tem_low[:-1])if tem_high[-1] ℃:temp.append(tem_high[:-1])else:temp.append(tem_high)wind inf[2].find_all(span) # 找到风向for j in wind:temp.append(j[title])wind_scale inf[2].find(i).string # 找到风级index1 wind_scale.index(级)temp.append(int(wind_scale[index1-1:index1]))final.append(temp)i i 1return final_day,final#print(final)
def get_content2(html):处理得到有用信息保存数据文件final [] # 初始化一个列表保存数据bs BeautifulSoup(html, html.parser) # 创建BeautifulSoup对象body bs.bodydata body.find(div, {!-- --id: 15d}) # 找到div标签且id 15dul data.find(ul) # 找到所有的ul标签li ul.find_all(li) # 找到左右的li标签final []i 0 # 控制爬取的天数for day in li: # 遍历找到的每一个liif i lt; 8:temp [] # 临时存放每天的数据date day.find(span,{!-- --class:time}).string # 得到日期date date[date.index()1:-2] # 取出日期号temp.append(date) weather day.find(span,{!-- --class:wea}).string # 找到天气temp.append(weather)tem day.find(span,{!-- --class:tem}).text # 找到温度temp.append(tem[tem.index(/)1:-1]) # 找到最低气温temp.append(tem[:tem.index(/)-1]) # 找到最高气温wind day.find(span,{!-- --class:wind}).string # 找到风向if 转 in wind: # 如果有风向变化temp.append(wind[:wind.index(转)])temp.append(wind[wind.index(转)1:])else: # 如果没有风向变化前后风向一致temp.append(wind)temp.append(wind)wind_scale day.find(span,{!-- --class:wind1}).string # 找到风级index1 wind_scale.index(级)temp.append(int(wind_scale[index1-1:index1]))final.append(temp)return finaldef write_to_csv(file_name, data, day14):保存为csv文件with open(file_name, a, errorsignore, newline) as f:if day 14:header [日期,天气,最低气温,最高气温,风向1,风向2,风级]else:header [小时,温度,风力方向,风级,降水量,相对湿度,空气质量]f_csv csv.writer(f)f_csv.writerow(header)f_csv.writerows(data)def main():主函数print(Weather test)# 珠海url1 http://www.weather.com.cn/weather/101280701.shtml # 7天天气中国天气网url2 http://www.weather.com.cn/weather15d/101280701.shtml # 8-15天天气中国天气网html1 getHTMLtext(url1)data1, data1_7 get_content(html1) # 获得1-7天和当天的数据html2 getHTMLtext(url2)data8_14 get_content2(html2) # 获得8-14天数据data14 data1_7 data8_14#print(data)write_to_csv(weather14.csv,data14,14) # 保存为csv文件write_to_csv(weather1.csv,data1,1)if __name__ __main__:main()data1_analysis.py:
# data1_analysis.py
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import math
def tem_curve(data):温度曲线绘制hour list(data[小时])tem list(data[温度])for i in range(0,24):if math.isnan(tem[i]) True:tem[i] tem[i-1]tem_ave sum(tem)/24 # 求平均温度 tem_max max(tem) tem_max_hour hour[tem.index(tem_max)] # 求最高温度tem_min min(tem)tem_min_hour hour[tem.index(tem_min)] # 求最低温度x []y []for i in range(0, 24):x.append(i)y.append(tem[hour.index(i)])plt.figure(1)plt.plot(x,y,colorred,label温度) # 画出温度曲线plt.scatter(x,y,colorred) # 点出每个时刻的温度点plt.plot([0, 24], [tem_ave, tem_ave], cblue, linestyle--,label平均温度) # 画出平均温度虚线plt.text(tem_max_hour0.15, tem_max0.15, str(tem_max), hacenter, vabottom, fontsize10.5) # 标出最高温度plt.text(tem_min_hour0.15, tem_min0.15, str(tem_min), hacenter, vabottom, fontsize10.5) # 标出最低温度plt.xticks(x)plt.legend()plt.title(一天温度变化曲线图)plt.xlabel(时间/h)plt.ylabel(摄氏度/℃)plt.show()def hum_curve(data):相对湿度曲线绘制hour list(data[小时])hum list(data[相对湿度])for i in range(0,24):if math.isnan(hum[i]) True:hum[i] hum[i-1]hum_ave sum(hum)/24 # 求平均相对湿度 hum_max max(hum) hum_max_hour hour[hum.index(hum_max)] # 求最高相对湿度hum_min min(hum)hum_min_hour hour[hum.index(hum_min)] # 求最低相对湿度x []y []for i in range(0, 24):x.append(i)y.append(hum[hour.index(i)])plt.figure(2)plt.plot(x,y,colorblue,label相对湿度) # 画出相对湿度曲线plt.scatter(x,y,colorblue) # 点出每个时刻的相对湿度plt.plot([0, 24], [hum_ave, hum_ave], cred, linestyle--,label平均相对湿度) # 画出平均相对湿度虚线plt.text(hum_max_hour0.15, hum_max0.15, str(hum_max), hacenter, vabottom, fontsize10.5) # 标出最高相对湿度plt.text(hum_min_hour0.15, hum_min0.15, str(hum_min), hacenter, vabottom, fontsize10.5) # 标出最低相对湿度plt.xticks(x)plt.legend()plt.title(一天相对湿度变化曲线图)plt.xlabel(时间/h)plt.ylabel(百分比/%)plt.show()def air_curve(data):空气质量曲线绘制hour list(data[小时])air list(data[空气质量])print(type(air[0]))for i in range(0,24):if math.isnan(air[i]) True:air[i] air[i-1]air_ave sum(air)/24 # 求平均空气质量 air_max max(air) air_max_hour hour[air.index(air_max)] # 求最高空气质量air_min min(air)air_min_hour hour[air.index(air_min)] # 求最低空气质量x []y []for i in range(0, 24):x.append(i)y.append(air[hour.index(i)])plt.figure(3)for i in range(0,24):if y[i] lt; 50:plt.bar(x[i],y[i],colorlightgreen,width0.7) # 1等级elif y[i] lt; 100:plt.bar(x[i],y[i],colorwheat,width0.7) # 2等级elif y[i] lt; 150:plt.bar(x[i],y[i],colororange,width0.7) # 3等级elif y[i] lt; 200:plt.bar(x[i],y[i],colororangered,width0.7) # 4等级elif y[i] lt; 300:plt.bar(x[i],y[i],colordarkviolet,width0.7) # 5等级elif y[i] gt; 300:plt.bar(x[i],y[i],colormaroon,width0.7) # 6等级plt.plot([0, 24], [air_ave, air_ave], cblack, linestyle--) # 画出平均空气质量虚线plt.text(air_max_hour0.15, air_max0.15, str(air_max), hacenter, vabottom, fontsize10.5) # 标出最高空气质量plt.text(air_min_hour0.15, air_min0.15, str(air_min), hacenter, vabottom, fontsize10.5) # 标出最低空气质量plt.xticks(x)plt.title(一天空气质量变化曲线图)plt.xlabel(时间/h)plt.ylabel(空气质量指数AQI)plt.show()def wind_radar(data):风向雷达图wind list(data[风力方向])wind_speed list(data[风级])for i in range(0,24):if wind[i] 北风:wind[i] 90elif wind[i] 南风:wind[i] 270elif wind[i] 西风:wind[i] 180elif wind[i] 东风:wind[i] 360elif wind[i] 东北风:wind[i] 45elif wind[i] 西北风:wind[i] 135elif wind[i] 西南风:wind[i] 225elif wind[i] 东南风:wind[i] 315degs np.arange(45,361,45)temp []for deg in degs:speed []# 获取 wind_deg 在指定范围的风速平均值数据for i in range(0,24):if wind[i] deg:speed.append(wind_speed[i])if len(speed) 0:temp.append(0)else:temp.append(sum(speed)/len(speed))print(temp)N 8theta np.arange(0.np.pi/8,2*np.pinp.pi/8,2*np.pi/8)# 数据极径radii np.array(temp)# 绘制极区图坐标系plt.axes(polarTrue)# 定义每个扇区的RGB值R,G,Bx越大对应的颜色越接近蓝色colors [(1-x/max(temp), 1-x/max(temp),0.6) for x in radii]plt.bar(theta,radii,width(2*np.pi/N),bottom0.0,colorcolors)plt.title(一天风级图,x0.2,fontsize20)plt.show()def calc_corr(a, b):计算相关系数a_avg sum(a)/len(a)b_avg sum(b)/len(b)cov_ab sum([(x - a_avg)*(y - b_avg) for x,y in zip(a, b)])sq math.sqrt(sum([(x - a_avg)**2 for x in a])*sum([(x - b_avg)**2 for x in b])) corr_factor cov_ab/sqreturn corr_factordef corr_tem_hum(data):温湿度相关性分析tem data[温度]hum data[相对湿度]plt.scatter(tem,hum,colorblue)plt.title(温湿度相关性分析图)plt.xlabel(温度/℃)plt.ylabel(相对湿度/%)plt.text(20,40,相关系数为str(calc_corr(tem,hum)),fontdict{!-- --size:10,color:red})plt.show()print(相关系数为str(calc_corr(tem,hum)))def main():plt.rcParams[font.sans-serif][SimHei] # 解决中文显示问题plt.rcParams[axes.unicode_minus] False # 解决负号显示问题data1 pd.read_csv(weather1.csv,encodinggb2312)print(data1)tem_curve(data1)hum_curve(data1)air_curve(data1)wind_radar(data1)corr_tem_hum(data1)
if __name__ __main__:main()data14_analysis.py:
# data14_analysis.py
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import mathdef tem_curve(data):温度曲线绘制date list(data[日期])tem_low list(data[最低气温])tem_high list(data[最高气温])for i in range(0,14):if math.isnan(tem_low[i]) True:tem_low[i] tem_low[i-1]if math.isnan(tem_high[i]) True:tem_high[i] tem_high[i-1]tem_high_ave sum(tem_high)/14 # 求平均高温 tem_low_ave sum(tem_low)/14 # 求平均低温 tem_max max(tem_high) tem_max_date tem_high.index(tem_max) # 求最高温度tem_min min(tem_low)tem_min_date tem_low.index(tem_min) # 求最低温度x range(1,15)plt.figure(1)plt.plot(x,tem_high,colorred,label高温) # 画出高温度曲线plt.scatter(x,tem_high,colorred) # 点出每个时刻的温度点plt.plot(x,tem_low,colorblue,label低温) # 画出低温度曲线plt.scatter(x,tem_low,colorblue) # 点出每个时刻的温度点plt.plot([1, 15], [tem_high_ave, tem_high_ave], cblack, linestyle--) # 画出平均温度虚线plt.plot([1, 15], [tem_low_ave, tem_low_ave], cblack, linestyle--) # 画出平均温度虚线plt.legend()plt.text(tem_max_date0.15, tem_max0.15, str(tem_max), hacenter, vabottom, fontsize10.5) # 标出最高温度plt.text(tem_min_date0.15, tem_min0.15, str(tem_min), hacenter, vabottom, fontsize10.5) # 标出最低温度plt.xticks(x)plt.title(未来14天高温低温变化曲线图)plt.xlabel(未来天数/天)plt.ylabel(摄氏度/℃)plt.show()
def change_wind(wind):改变风向for i in range(0,14):if wind[i] 北风:wind[i] 90elif wind[i] 南风:wind[i] 270elif wind[i] 西风:wind[i] 180elif wind[i] 东风:wind[i] 360elif wind[i] 东北风:wind[i] 45elif wind[i] 西北风:wind[i] 135elif wind[i] 西南风:wind[i] 225elif wind[i] 东南风:wind[i] 315return winddef wind_radar(data):风向雷达图wind1 list(data[风向1])wind2 list(data[风向2])wind_speed list(data[风级])wind1 change_wind(wind1)wind2 change_wind(wind2)degs np.arange(45,361,45)temp []for deg in degs:speed []# 获取 wind_deg 在指定范围的风速平均值数据for i in range(0,14):if wind1[i] deg:speed.append(wind_speed[i])if wind2[i] deg:speed.append(wind_speed[i])if len(speed) 0:temp.append(0)else:temp.append(sum(speed)/len(speed))print(temp)N 8theta np.arange(0.np.pi/8,2*np.pinp.pi/8,2*np.pi/8)# 数据极径radii np.array(temp)# 绘制极区图坐标系plt.axes(polarTrue)# 定义每个扇区的RGB值R,G,Bx越大对应的颜色越接近蓝色colors [(1-x/max(temp), 1-x/max(temp),0.6) for x in radii]plt.bar(theta,radii,width(2*np.pi/N),bottom0.0,colorcolors)plt.title(未来14天风级图,x0.2,fontsize20)plt.show()def weather_pie(data):绘制天气饼图weather list(data[天气])dic_wea {!-- -- }for i in range(0,14):if weather[i] in dic_wea.keys():dic_wea[weather[i]] 1else:dic_wea[weather[i]] 1print(dic_wea)explode[0.01]*len(dic_wea.keys())color [lightskyblue,silver,yellow,salmon,grey,lime,gold,red,green,pink]plt.pie(dic_wea.values(),explodeexplode,labelsdic_wea.keys(),autopct%1.1f%%,colorscolor)plt.title(未来14天气候分布饼图)plt.show()def main():plt.rcParams[font.sans-serif][SimHei] # 解决中文显示问题plt.rcParams[axes.unicode_minus] False # 解决负号显示问题data14 pd.read_csv(weather14.csv,encodinggb2312)print(data14)tem_curve(data14)wind_radar(data14)weather_pie(data14)if __name__ __main__:main()