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()