Programa Python para analisis usando grafico con barras de error

import datetime as dt

import matplotlib.pyplot as plt

import sys

import numpy as np


station=sys.argv[1]

print(station)



WSPR_file=open("/home/andres/WSPR/"+station+".txt",'r')

date_list=[]

hour_list=[]

SNR_list=[]

for l in WSPR_file:

line=l.split()

date_list.append(dt.datetime.strptime(line[0]+' '+line[1],"%Y-%m-%d %H:%M"))#convert string date to datetime format

hour_list.append(line[1])

SNR_list.append(line[4])



init_date=min(date_list) #search min and max dates of the list of reports, from datetime list of objects

print(init_date)

end_date=max(date_list)

print(end_date)


h_list=[]

hourly=[]


init_time=dt.datetime.strptime("00:00","%H:%M")

for i in hour_list:

time=dt.datetime.strptime(i,"%H:%M")

h_list.append(((time-init_time).total_seconds())/3600)


h=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]

h_m=[0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5,11.5,12.5,13.5,14.5,15.5,16.5,17.5,18.5,19.5,20.5,21.5,22.5,23.5]

mean=[]

stdev=[]

for i in range(0,24):

WSPR_file2=open("/home/andres/WSPR/"+station+".txt",'r')

signal=[]

for l in WSPR_file2:

a=l.split()

if(dt.datetime.strptime(a[0]+' ' +a[1],"%Y-%m-%d %H:%M").hour==i):

signal.append(int(a[4]))

if (len(signal)!=0):

mu=np.mean(signal)

dev=np.std(signal)

else:

mu=-30.0

dev=0.0

mean.append(mu)

stdev.append(dev)

WSPR_file.close()


x=h_list

y=SNR_list

y_int=[]


x_min=0

x_max=24

for i in y: #generate list in int format for SNR levels

y_int.append(int(i))


y_min=min(y_int) #Only works min() if integer

y_max=max(y_int)



fig, axs = plt.subplots(ncols=1, sharey=True, figsize=(7, 4))

fig.subplots_adjust(hspace=0.5, left=0.07, right=0.97, top=0.9)


ax = axs

ax.errorbar(h_m,mean,xerr=0.5,yerr=stdev,fmt="o")

ax.set_xlim(left=0,right=24)

ax.set_xlabel("UTC time")

ax.set_ylabel("Signal to Noise Ratio (dB)")

ax.set_title("WSPR Analysis of LU3HO received by "+station+" from "+str(init_date)+" to "+str(end_date)+"\nError bars: Vertical=1 sigma, horizontal= 1 hour")

ax.set_xticks([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24])

ax.set_yticks([-30,-25,-20,-15,-10,-5,0,5,10])



plt.show()