代码拉取完成,页面将自动刷新
import csv
from matplotlib import pyplot as plt
from matplotlib.font_manager import FontProperties
font_set = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=12)
filename = '上海天气.csv'
with open(filename) as f:
reader = csv.reader(f)
header_row = next(reader)
highs,lows,times = [],[],[]
for row in reader:
#1去除掉单位转换为数字;2将华氏温度转换为摄氏温度
high = round((5/9)*(int(row[1][:-1])-32),2)
low = round((5/9)*(int(row[2][:-1])-32),2)
highs.append(high)
lows.append(low)
times.append(row[0])
#print(times)
#根据数据绘制图形
fig = plt.figure(dpi=128,figsize=(11,5))
plt.plot(times,highs,c='red',alpha=0.5)
plt.plot(times,lows,c='blue',alpha=0.5)
plt.fill_between(times,highs,lows,facecolor='green',alpha=0.1)
#倾斜横坐标,防止相邻的数据重叠
fig.autofmt_xdate()
#设置图形格式
plt.title("上海2018-08-14天气",fontproperties=font_set)
plt.xlabel('时间',fontsize=16,fontproperties=font_set)
plt.ylabel("气温(F)",fontsize=16,fontproperties=font_set)
plt.tick_params(axis='both',which='major',labelsize=7)
plt.show()
#打印标题行
#print(header_row)
#for index,column_header in enumerate(header_row):
#print(index,column_header)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。