气温图#导入模块 csv 后import csvfrom datetime import datetimefrom matplotlib import pyplot as plt#将要使用的文件的名称存储在 filename 中filename='sitka_weather_2014.csv'#打开这个文件,并将结果文件对象存储在 f 中with open(filename) as f:#调用 csv.reader() ,并将前面存储的文件对象作为实参传递给它# 从而创建一个与该文件相关联的阅读器( reader )对象 reader=csv.reader(f)#调用next()并将阅读器对象传递给它时,得到的是文件的第一行,其中包含文件头 header_row=next(reader)#创建三个列表dates,highs,lows,将日期时间,最高气温,最低气温,分别记录到三个列表当中 dates,highs,lows=[],[],[] for row in reader: # 针对 ValueError 异常,打印一条错误消息, # 指出缺失数据的日期 try: #设置日期格式为****-**-**,Python中的第一列为第0列 # 所以高温数据中的1代表CSV文件中的第二列,以下依次类推 current_date=datetime.strptime(row[0],"%Y-%m-%d") high=int(row[1]) low=int(row[3]) except ValueError: print(current_date,'missing data') else: dates.append(current_date) highs.append(high) lows.append(low)#设置图纸的分辨率和图纸大小,绘制日期、高温、低温折线图,颜色,透明度fig=plt.figure(dpi=12
流线动态图python_python学习笔记:矢量场流线图和气温图
最新推荐文章于 2024-06-23 19:24:22 发布