po上一个以前写的,没有po上来的脚本,主要是怕以后找不到了QAQ
import sys,re,argparse
import matplotlib.pyplot as plt
parser = argparse.ArgumentParser()
parser.add_argument('--inputfile',type = str)
parser.add_argument('--parament',type = str)
namespace = parser.parse_args()
environment = namespace.parament
f = open(namespace.inputfile,"r")
title=f.readline().split()
for i in range(len(title)):
if title[i]==environment:
environment=i+2
def get_colunm_pyre(f,xlist,split_flag=None): #get the col
line=[]
for i in f:
i=i.strip("\n")
m=i.split(split_flag)
#print (m[0],len(m))
for k in range(len(xlist)):
try:
line.append(m[xlist[k]-1])
except:
print(m[0])
break
#line.append("\n")
return line
def match_by_str(f,str_match): #get the row
pattern=re.compile(str_match)
line=[]
for i in f:
#if str_match in i:
m=pattern.search(i)
while m:
line.append(i)
m=False
return line
f = open(namespace.inputfile,"r") #open the file
#get the col
xlist=[8,environment]
line = get_colunm_pyre(f,xlist,"\t")
f.close()
#display the data
draw={}
for i in range(0,len(line),2):
if line[i+1] != "None":
draw[line[i]]=line[i+1]
else:
continue
time = list(draw.keys())
#print(len(draw))
data = list(draw.values())
data_int = []
for t in data:
data_int.append(float(t))
data = data_int
avg = sum(data)/len(data)
for t in time:
if float(draw[t])>=2*avg:
del draw[t]
day = []
time = []
time = list(draw.keys())
for i in time:
a = i.split(",")
day.append(a[0])
day=list(set(day))
day.sort()
#print(day)
low={}
high={}
for i in day:
num=[]
line = match_by_str(time,i)
#print(line)
for k in line:
num.append(float(draw[k]))
#print(min(num))
low[i] = min(num)
high[i] = max(num)
draw_y1=[]
draw_y2=[]
draw_x=day
for i in day:
draw_y1.append(low[i])
draw_y2.append(high[i])
'''
def adjust_list(draw_y1):
for i in range(len(draw_y1)):
if draw_y1[i]>=2*(sum(draw_y1)/len(draw_y1)):
draw_y1[i] = sum(draw_y1)/len(draw_y1)
return(draw_y1)
draw_y1 = adjust_list(draw_y1)
draw_y2 = adjust_list(draw_y2)
'''
f.close()
print(draw_y1,"\n",draw_y2)
##draw
fig = plt.figure(figsize=(10,6))
plt.plot(draw_x,draw_y1,c='blue',alpha=0.5)
plt.plot(draw_x,draw_y2,c='red',alpha=0.5)
#plt.fill_between(low.keys(),high.values(),low.values(),facecolor='orange',alpha=0.3)
#title = title1[parament-1]
plt.title("{},{}:{}".format(title[environment-2],title[20],title[21]),fontsize=24)
plt.xlabel('Dates',fontsize=14)
#绘制倾斜的日期标签
fig.autofmt_xdate()
plt.ylabel('Temperature(℃)',fontsize=14)
#设置坐标轴参数
plt.tick_params(axis='both',which='major',labelsize=10)
plt.show()