2018年大数据比赛本科组 第4题数据可视化 有关气象信息

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from pandas import Series,DataFrame

# 第一问:通过折线图展示2018年9月份天每天最高温度变化图和最低温度变化图
df = pd.read_table('weather.txt')
df_new = df.loc[df['date']>'2018-9-0']
s1 = df_new.pivot_table(index='date',values=['maxtemp'])
s1.plot()
plt.rcParams['font.sans-serif']=['SimHei']
plt.title('九月最高气温折线图')
plt.xlabel('x轴')
plt.ylabel('y轴')
plt.savefig('1.png')
plt.show()
s2 = df_new.pivot_table(index='date',values=['mintemp'])
s2.plot()
plt.rcParams['font.sans-serif']=['SimHei']
plt.title('九月最低气温折线图')
plt.xlabel('x轴')
plt.ylabel('y轴')
plt.savefig('3.png')
plt.show()

# 第二问:通过雷达图展示2017年和2018年天气概况信息(雷达图中所统计的6种天气概况分别为:
# 多云,雷阵雨,小雨,晴,阴,中雨;这6种天气概况最大极限值为:200)
df_weather = df.loc[df['date']>'2017-1-0']
df_new1 = df_weather.loc[df['weather']=='多云']
# df_new1 = df.loc[(df['weather']=='晴')&(df['date']>'2017-1-0')]:这一句和上面两句结果一样
df_new2 = df_weather.loc[df['weather']=='雷阵雨']
df_new3 = df_weather.loc[df['weather']=='小雨']
df_new4 = df_weather.loc[df['weather']=='晴']
df_new5 = df_weather.loc[df['weather']=='阴']
df_new6 = df_weather.loc[df['weather']=='中雨']
tp_D1 = DataFrame(df_new1)
tp_D2 = DataFrame(df_new2)
tp_D3 = DataFrame(df_new3)
tp_D4 = DataFrame(df_new4)
tp_D5 = DataFrame(df_new5)
tp_D6 = DataFrame(df_new6)
print(tp_D1["weather"].count())
print(tp_D2["weather"].count())
print(tp_D3["weather"].count())
print(tp_D4["weather"].count())
print(tp_D5["weather"].count())
print(tp_D6["weather"].count())
#雷达图
datalenth = 6
data = np.array([210,146,52,70,43,37])
angles = np.linspace(0,2*np.pi,datalenth,endpoint=False)
data = np.concatenate((data,[data[0]]))
angles = np.concatenate((angles,[angles[0]]))
fig = plt.figure()
ax = fig.add_subplot(111,polar=True)
ax.plot(angles,data,'bo-',linewidth=2)
ax.set_thetagrids(angles*180/np.pi,fontproperties='SimHei')
ax.set_title("2017年和2018年天气概况雷达图",va='bottom',fontproperties='SimHei')
ax.grid(True)
plt.savefig('5.png')
plt.show()

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值