赞
踩
python可视化学习笔记,代码在下面。
import csv from matplotlib import pyplot as plt from datetime import datetime filename="death_valley_2014.csv" #从文件中获取日期和最高气温 with open(filename) as f: reader = csv.reader(f) #读取第一行数据 header_row=next(reader) #每一行为一个列表,读取每个列表的第二个元素 dates,highs,lows=[],[],[] for row in reader: try: current_date=datetime.strptime(row[0],'%Y-%m-%d') high=int(row[1]) low=int(row[3]) except: print('未知错误') else: lows.append(low) dates.append(current_date) highs.append(high) #设置分辨率跟窗口区域大小 fig=plt.figure(dpi=128,figsize=(10,5)) #将列表传给plot,alpha表示透明度(0-1) plt.plot(dates,highs,c='red') plt.plot(dates,lows,c='blue') plt.fill_between(dates,highs,lows,facecolor='yellow',alpha=0.5) #设置图表的格式 plt.title('biaoti') plt.xlabel('x',fontsize=15) #倾斜的 fig.autofmt_xdate() plt.ylabel('y',fontsize=15) plt.tick_params(axis='both',labelsize=10) #显示图表 plt.show()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。