############################################################################### # CARGAMOS LAS LIBRERIAS DE FUNCIONES HECHAS QUE VAMOS A USAR ############################################################################### import numpy as np #PARA HACER CUENTAS import xlrd #PARA CARGAR ARCHIVOS DE EXCEL import matplotlib.pyplot as plt #PARA GRAFICAR plt.close('all') #CIERRA CUALQUIER GRAFICO QUE HAYA ABIERTO ############################################################################### # DEFINIMOS NOSOTROS OTRAS DE LAS FUNCIONES QUE VAYAMOS A USAR ############################################################################### # FUNCION PARA ABRIR UNA COLUMNA DE UN ARCHIVO DE EXCEL def abrir_columna_excel(nombre_archivo,columna): wb = xlrd.open_workbook(nombre_archivo) Hoja1 = wb.sheet_by_index(0) N_datos=len(Hoja1.col_values(columna)) datos=[] for i in range(1,N_datos): if type(Hoja1.cell_value(i, columna))==float: datos.append(Hoja1.cell_value(i, columna)) return datos # FUNCION PARA GRAFICAR MUCHOS HISTOGRAMAS Y COMPARARLOS def graficar_histogramas(lista_datos): colores=['blue','green','red','cyan','magenta'] plt.figure() x_min=10**10 x_max=0 y_min=10**10 y_max=0 for i in range(len(lista_datos)): plt.subplot(len(lista_datos),1,i+1) datos=lista_datos[i] histo=plt.hist(datos,color=colores[i],alpha=0.65,label='Datos n° '+str(i)) mediana=np.median(datos) plt.plot([mediana, mediana],[0,np.max(histo[0])],color=colores[i]) intervalo_50=[np.percentile(datos,25),np.percentile(datos,75)] plt.axvspan(intervalo_50[0],intervalo_50[1], alpha=0.25, color=colores[i]) intervalo_95=[np.percentile(datos,2.5),np.percentile(datos,97.5)] plt.axvspan(intervalo_95[0],intervalo_95[1], alpha=0.10, color=colores[i]) plt.legend() x_min=np.min([x_min,plt.xlim()[0]]) x_max=np.max([x_max,plt.xlim()[1]]) y_min=np.min([y_min,plt.ylim()[0]]) y_max=np.max([y_max,plt.ylim()[1]]) for i in range(len(lista_datos)): plt.subplot(len(lista_datos),1,i+1) plt.axis([x_min,x_max,y_min,y_max]) plt.show() ############################################################################### # ESCRIBIMOS LA SECUENCIA DE PROCESOS DE NUESTRO PROGRAMA ############################################################################### nombre_archivo = ("C:\\Users\\Usuario\\Dropbox\\Clase Estadística\\mediciones.xlsx") columna=0 datos_0=abrir_columna_excel(nombre_archivo,columna) columna=1 datos_1=abrir_columna_excel(nombre_archivo,columna) columna=2 datos_2=abrir_columna_excel(nombre_archivo,columna) lista_datos=[datos_0,datos_1,datos_2] graficar_histogramas(lista_datos) #N_datos=10000 #datos=np.random.normal(10,1,N_datos)