├── Links ├── Falling raindrop velocity.py ├── README.md ├── Water Vapor Calculation.py ├── Rainfall bar plot.py ├── Graficando vectores con magnitud.py ├── Detección de umbrales en series.py ├── Cumulative Rainfall.py ├── Gráficos Interiores.py ├── 2D Spatial interpolation.py ├── Lluvia mensual.py ├── Creando un nuevo gráfico.py ├── Normal Depth-Manning.py ├── Polynomial Regression.py ├── Flow Routing-Muskingum.py ├── Histogramas.py ├── Infiltration.py ├── Curvas de Nivel y Pie Chart.py ├── Raingauges spatial distribution and interpolation.py ├── Gráficos Scatter-Superpuesto-Regresión.py ├── NDVI Calculation.py ├── Gráficos interiores y doble eje.py ├── Evaporation calculation.py └── Gráfico de lluvia.py /Links: -------------------------------------------------------------------------------- 1 | gráficos internos: 2 | https://matplotlib.org/gallery/subplots_axes_and_figures/axes_demo.html#sphx-glr-gallery-subplots-axes-and-figures-axes-demo-py 3 | -------------------------------------------------------------------------------- /Falling raindrop velocity.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | Re = 5.0; rho_w = 998; rho_a = 1.2; g = 9.8; D = 0.05E-3 3 | Cd = 24/Re 4 | Vt = np.sqrt((4*g*D)/(3*Cd)*(rho_w/rho_a-1)) 5 | Vt 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python-hydrology-training 2 | Some training examples for python programming in hydrology and climatology. 3 | References: 4 | Kumar, S. (2011) - Python for Hydrology / GNU Free Documentation License. 5 | -------------------------------------------------------------------------------- /Water Vapor Calculation.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | T = np.linspace(-100,100,50) 3 | es = 611*np.exp(17.27*T/(237.3+T)) 4 | plt.plot(T,es) 5 | plt.xlabel('T (degree Celcius)') 6 | plt.ylabel('es (Pa)') 7 | plt.show() 8 | -------------------------------------------------------------------------------- /Rainfall bar plot.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | time = np.linspace(0,100,21) # create time variable 3 | rainfall = np.random.rand(21) # generate rainfall 4 | import matplotlib.pyplot as plt 5 | plt.bar(time,rainfall) 6 | plt.xlabel('Time') 7 | plt.ylabel('Incremental rainfall') 8 | plt.savefig('rain.png') #buscar en la ruta C:\Users\monte\.spyder-py3 ó en C:\Users\monte\.spyder-py2 9 | -------------------------------------------------------------------------------- /Graficando vectores con magnitud.py: -------------------------------------------------------------------------------- 1 | plt.ion() 2 | lon = np.arange(15) - 10. 3 | lat = np.arange(15) + 30. 4 | lon, lat = np.meshgrid(lon, lat) 5 | u = np.random.randn(15 * 15) 6 | v = np.random.randn(15 * 15) 7 | colores = ['k','r','b','g','c','y','gray’] 8 | plt.title('Flechas de un viento un poco loco') plt.xlabel('longitud') 9 | plt.ylabel('latitud') 10 | plt.quiver(lon, lat, u, v, color = colores) 11 | -------------------------------------------------------------------------------- /Detección de umbrales en series.py: -------------------------------------------------------------------------------- 1 | plt.ion() 2 | x = np.arange(100) 3 | y = np.random.rand(100) 4 | plt.plot(x,y, color = 'black', label = '(x, f(x)’) 5 | plt.plot(x[y > 0.9], y[y > 0.9], 'bo', label = 'f(x) > 0.9’) -> marcador azul 6 | plt.axhspan(0.9, 1, alpha = 0.1) -> borrar el área del gráfico 7 | plt.ylim(0,1.2) 8 | plt.legend() 9 | plt.title(u'Representación de (x, f(x))’) 10 | plt.xlabel('valores x 11 | plt.ylabel('valores f(x)') 12 | -------------------------------------------------------------------------------- /Cumulative Rainfall.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | time = np.linspace(0,100,21) # create time variable 4 | rainfall = np.random.rand(21) # generate rainfall 5 | cum_rainfall = np.cumsum(rainfall) 6 | plt.clf() 7 | plt.plot(time,cum_rainfall) 8 | plt.xlabel('Time') 9 | plt.ylabel('Cummulative rainfall') 10 | plt.savefig('cum_rain.png') #buscar el archivo en la ruta C:\Users\monte\.spyder-py3 ó C:\Users\monte\.spyder-py2 11 | -------------------------------------------------------------------------------- /Gráficos Interiores.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt #importar módulo 2 | import numpy as np 3 | plt.ion() # Nos ponemos en modo interactivo 4 | plt.axes(facecolor='w') #crear ventana de gráfico con color de fondo 5 | plt.plot(np.exp(np.linspace(0,10,100))) #linspace: secuencia de datos 6 | plt.axes([0.2,0.55,0.3,0.3],facecolor='gray')#crear ventana de gráfico interior con color de fondo 7 | plt.plot(np.sin(np.linspace(0,10,100)), 'b-o', linewidth = 2,color='blue') 8 | -------------------------------------------------------------------------------- /2D Spatial interpolation.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import numpy as np 3 | import scipy as sp #debemos de importar scipy 4 | from scipy.interpolate import Rbf 5 | 6 | x = np.random.rand(5) 7 | y = np.random.rand(5) 8 | pet = 2+2*np.random.rand(5) 9 | rbfi =Rbf(x, y, pet) 10 | 11 | xi = np.linspace(0,1) 12 | yi = np.linspace(0,1) 13 | XI, YI = np.meshgrid(xi,yi) # gridded locations 14 | di = rbfi(XI, YI) # interpolated values 15 | plt.imshow(di, extent=(0,1,0,1), origin='lower') 16 | plt.scatter(x,y, color='k') 17 | plt.xlabel('X') 18 | plt.ylabel('Y') 19 | plt.axis((0,1,0,1)) 20 | plt.savefig('rbf.png') 21 | -------------------------------------------------------------------------------- /Lluvia mensual.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import numpy as np 3 | plt.ion() 4 | import calendar 5 | dias = [np.array(calendar.mdays)[0:i].sum() + 1 for i in np.arange(12)+1] 6 | meses = calendar.month_name[1:13] 7 | plt.axes([0.1,0.2,0.8,0.65]) 8 | plt.plot(np.arange(1,366),np.random.rand(365), label = 'valores al azar') 9 | plt.xlim(-5,370) 10 | plt.ylim(0,1.2) 11 | plt.legend() 12 | plt.title(u'Ejemplo de título') 13 | plt.suptitle(u'Ejemplo de título superior') 14 | plt.minorticks_on() 15 | plt.xticks(dias, meses, size = 'small', color = 'b', rotation = 45) 16 | plt.xlabel(u't (días)') 17 | plt.ylabel('Media diaria') 18 | -------------------------------------------------------------------------------- /Creando un nuevo gráfico.py: -------------------------------------------------------------------------------- 1 | ##Importamos Librerias## 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | 5 | #Creamos la nube de puntos 6 | x = np.array([0, 1, 2, 3]) 7 | y = np.array([1, 1.5, 1.8, 2.6]) 8 | 9 | #Construimos una matriz 10 | A = np.vstack([x, np.ones(len(x))]) 11 | A = A.T #Hacemos su traspuesta 12 | 13 | #Obtenemos parametros de la recta 14 | m, c = np.linalg.lstsq(A, y)[0] 15 | print ("La recta obtenida es: y = " + str(m) + "x + " + str(c)) 16 | 17 | 18 | plt.plot(x, y, 'o', label='Nube puntos', markersize=15) 19 | plt.plot(x, m*x + c, 'r', label='Regresion Lineal') 20 | plt.legend() 21 | plt.show() 22 | 23 | raw_input("Enter para salir") 24 | -------------------------------------------------------------------------------- /Normal Depth-Manning.py: -------------------------------------------------------------------------------- 1 | # importamos primeramente los módulos a usar 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | from scipy.optimize import fmin 5 | 6 | # definimos variables 7 | n = 0.015 #coeficiente de rugosidad de Manning 8 | S0 = 0.025 # Pendiente de fondo=línea de energía en flujo uniforme 9 | Q = 9.26 #Caudal que escurre por el canal 10 | B = 2 #Base del canal 11 | 12 | # definiendo la función para el cálculo del tirante normal 13 | def flow(y): 14 | Q_estimated = (1.49/n)*(S0**0.5)*((B*y)**(5/3))/((B+y)**(2/3)) 15 | epsilon = np.abs(Q_estimated - Q) 16 | return epsilon 17 | y_optimum = fmin(flow,0.1) 18 | 19 | #veamos algunos detalles del cálculo 20 | print(y_optimum) 21 | -------------------------------------------------------------------------------- /Polynomial Regression.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | # generate data 3 | x = np.linspace(0,10) 4 | y = 1 + 2*x - 3*x**2 + 15*np.random.randn(50) #aquí deberían ir los datos obtenidos experimentalmente 5 | # fit the polynomial 6 | z = np.polyfit(x,y,2) # aquí se hace el ajuste polinómico con regresión,cambiando el exponente 7 | print(z) 8 | 9 | import matplotlib.pyplot as plt 10 | # evaluate polynomial 11 | p = np.poly1d(z) 12 | z_true = np.array([-3, 2, 1]) # coefficient of true polynomial 13 | p_true = np.poly1d(z_true) # true polynomial 14 | # plot 15 | plt.plot(x, y,'.r', label='noisy data') 16 | plt.plot(x, p_true(x), label='True curve') 17 | plt.plot(x, p(x), label='Fitted curve') 18 | plt.xlabel('x') 19 | plt.ylabel('y') 20 | plt.legend() 21 | -------------------------------------------------------------------------------- /Flow Routing-Muskingum.py: -------------------------------------------------------------------------------- 1 | # importamos primeramente los módulos a usar 2 | from __future__ import division 3 | import numpy as np 4 | 5 | # definimos variables 6 | I = np.array([93, 137, 208, 320, 442, 546, 630, 678, 691, 675, 634, 571, 477, 7 | 390, 329, 247, 184, 134, 108, 90]) 8 | C1 = 0.0631 9 | C2 = 0.3442 10 | C3 = 0.5927 11 | 12 | Q = np.empty(20) # definimos un array vacío 13 | Q[0] = 85 # valor inicial del caudal 14 | 15 | # aplicamos un bucle 16 | for i in range(1,20): 17 | Q[i] = C1*I[i] + C2*I[i-1] + C3*Q[i-1] 18 | 19 | #ahora graficamos 20 | import matplotlib.pyplot as plt 21 | plt.plot(I, '-*', label='Inflow') 22 | plt.plot(Q, '--s', label='Outflow') 23 | plt.xlabel('Time', fontsize=20) 24 | plt.ylabel('Flow', fontsize=20) 25 | plt.legend() 26 | plt.savefig('muskingum.png') 27 | -------------------------------------------------------------------------------- /Histogramas.py: -------------------------------------------------------------------------------- 1 | #Un histograma es un gráfico de barras donde se representa la ocurrencia de datos 2 | #(frecuencia) en intervalos definidos. Lo que hace plt.hist es dibujar el histograma de 3 | #un vector en función del número de intervalos (bins) que definamos: 4 | 5 | plt.ion() 6 | x = np.random.randn(10000) #vector de números aleatorios de una distribución normal 7 | plt.hist(x, bins = 20) #histograma en 20 intervalos del mismo ancho 8 | 9 | #Para los gráficos de barras recurrimos a plt.bar : 10 | 11 | import datetime as dt 12 | prima = 600 + np.random.randn(5) * 10 13 | fechas=(dt.date.today()-dt.timedelta(5))+dt.timedelta(1)*np.arange(5) 14 | plt.axes((0.1, 0.3, 0.8, 0.6)) 15 | plt.bar(np.arange(5), prima) 16 | plt.ylim(550,650) 17 | plt.title('prima de riesgo') 18 | plt.xticks(np.arange(5), fechas, rotation = 45) 19 | 20 | 21 | -------------------------------------------------------------------------------- /Infiltration.py: -------------------------------------------------------------------------------- 1 | from __future__ import division 2 | import numpy as np 3 | # define the variables 4 | theta_e = 0.486 5 | psi = 16.7 6 | K = 0.65 7 | S_e = 0.3 8 | t = 1 9 | 10 | #calcular dtheta 11 | dtheta = (1-S_e)*theta_e 12 | 13 | # Primera iteración para F 14 | F_old = K*t 15 | epsilon = 1 16 | F = [] 17 | while epsilon > 1e-4: 18 | F_new = psi*dtheta * np.log(1+F_old/(psi*dtheta)) + K*t 19 | epsilon = F_new - F_old 20 | F_old = F_new 21 | F.append(F_new) 22 | #El valor iterado de F se almacena utilizando el método de adjuntar (append) 23 | #append adjunta el array por un solo elemento y coloca la variable de entrada en ella. 24 | 25 | #Ahora graficamos 26 | import matplotlib.pyplot as plt 27 | plt.plot(F,'-ok') 28 | plt.xlabel('número de iteraciones',fontsize=25) 29 | plt.ylabel('F',fontsize=20) 30 | plt.savefig('F.png') 31 | -------------------------------------------------------------------------------- /Curvas de Nivel y Pie Chart.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import numpy as np 3 | plt.ion() 4 | visitas = [43.97, 9.70, 7.42, 6.68, 3.91, 3.85, 5 | 3.62, 3.43, 3.16, 3.04] 6 | # Definimos un vector con el % de visitas del top ten de países 7 | visitas = np.append(visitas, 100. - np.sum(visitas)) 8 | paises = [u'España', u'México', 'Chile', 'Argentina’, 'Colombia’, 9 | 'Ecuador', u'Perú', 'USA', 'Islandia', 'Venezuela', 'Otros’] 10 | explode = [0, 0, 0, 0, 0, 0, 0, 0.2, 0.2, 0, 0] 11 | plt.pie(visitas, labels = paises, explode = explode) 12 | plt.title(u'Porcentaje de visitas por país') 13 | 14 | 15 | #Gráfico de curvas de nivel 16 | #Ahora nos apoyaremos de plt.contour y plt.contourf: 17 | 18 | plt.ion() 19 | x = np.random.rand(20) 20 | y = np.random.rand(20) 21 | t = np.random.rand(20)*3000 22 | plt.tricontourf(x, y, t) 23 | plt.tricontour(x, y, t, colors = 'k’) 24 | plt.scatter(x, y) 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Raingauges spatial distribution and interpolation.py: -------------------------------------------------------------------------------- 1 | # importar los módulos requeridos en este ejemplo 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | 5 | #generar ubicaciones y valores de lluvia 6 | x = np.random.rand(10) 7 | y = np.random.rand(10) 8 | rain = 10*np.random.rand(10) 9 | 10 | #graficar la distribución espacial 11 | plt.scatter(x,y) 12 | plt.xlabel('X') 13 | plt.ylabel('Y') 14 | plt.savefig('ubicación_estaciones.png') 15 | 16 | #Ahora interpolaremos 17 | from scipy.interpolate import griddata # usaremos la función griddata de la librería scipy.interpolate 18 | 19 | #generamos la malla de interpolación 20 | X,Y = np.meshgrid(np.linspace(0,1,1000), np.linspace(0,1,1000)) #usaremos la función meshgrid de la librería numpy 21 | 22 | #generamos el elemento grillado de precipitación 23 | grid_rain = griddata((x,y), rain, (X, Y)) 24 | 25 | #Ahora graficamos 26 | plt.clf() 27 | plt.contourf(X,Y,grid_rain) 28 | plt.colorbar() 29 | plt.xlabel('X') 30 | plt.ylabel('Y') 31 | -------------------------------------------------------------------------------- /Gráficos Scatter-Superpuesto-Regresión.py: -------------------------------------------------------------------------------- 1 | #Generación de gráficos con regresión lineal, superpuestos y scatter 2 | ##Importamos Librerias## 3 | import numpy as np 4 | import matplotlib.pyplot as plt 5 | 6 | #Creamos la nube de puntos 7 | x = np.array([0, 1, 2, 3]) 8 | y = np.array([1, 1.5, 1.8, 2.6]) 9 | 10 | #Construimos una matriz 11 | A = np.vstack([x, np.ones(len(x))]) 12 | A = A.T #Hacemos su traspuesta 13 | 14 | #Obtenemos parametros de la recta 15 | m, c = np.linalg.lstsq(A, y)[0] 16 | print ("La recta obtenida es: y = " + str(m) + "x + " + str(c)) 17 | 18 | 19 | plt.plot(x, y, 'o', label='Nube puntos', markersize=15) 20 | plt.plot(x, m*x + c, 'r', label='Regresion Lineal') 21 | plt.legend() 22 | plt.show() 23 | 24 | raw_input("Enter para salir") 25 | 26 | #Veamos un ejemplo de crear dos gráficos superpuestos: 27 | plt.plot(np.random.rand(10)) 28 | plt.plot(np.random.rand(10)) 29 | plt.show() 30 | 31 | #Ahora crearemos dos ventanas interactivas simultáneamente: 32 | plt.figure('scatter') #Ventana 33 | plt.figure('plot') 34 | a = np.random.rand(100) #Vector 35 | b = np.random.rand(100) 36 | plt.figure('scatter') 37 | plt.scatter(a,b) #Un scatterplot 38 | plt.figure('plot') 39 | plt.plot(a,b) 40 | -------------------------------------------------------------------------------- /NDVI Calculation.py: -------------------------------------------------------------------------------- 1 | from __future__ import division 2 | from osgeo import gdal 3 | from osgeo.gdalconst import* 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | driver = gdal.GetDriverByName('GTiff') 7 | file_name = "C:\\TEMPORAL\\LE07_L1TP_002071_20120211_20161204_01_T1_sr_band3.tif" #debes cargar el archivo ráster de la banda 3 8 | dataset = gdal.Open("C:\\TEMPORAL\\LE07_L1TP_002071_20120211_20161204_01_T1_sr_band3.tif",1) 9 | geotransform = dataset.GetGeoTransform() 10 | projection = dataset.GetProjection() 11 | band3 = dataset.GetRasterBand(1).ReadAsArray() 12 | dataset = None 13 | file_name = "C:\\TEMPORAL\\LE07_L1TP_002071_20120211_20161204_01_T1_sr_band4.tif" #debes cargar el archivo ráster de la banda 4 14 | dataset = gdal.Open("C:\\TEMPORAL\\LE07_L1TP_002071_20120211_20161204_01_T1_sr_band4.tif",1) 15 | band4 = dataset.GetRasterBand(1).ReadAsArray() 16 | dataset = None 17 | print(geotransform) 18 | print(projection) 19 | print(band3.dtype) 20 | ndvi = (band4-band3)/(band4+band3) 21 | #En caso hayan divisiones entre cero: "Divide by zero encountered" 22 | #np.seterr(divide='ignore') 23 | #mask = (band4+band3)==0 24 | #ndvi = np.zeros(band3.shape) 25 | #ndvi[ mask ] = -99 26 | #ndvi[ ~mask ] = ((band4-band3)/(band4+band3))[ ~mask ] 27 | plt.matshow(ndvi,cmap=plt.cm.jet, vmin=-1, vmax=1) 28 | plt.colorbar(shrink=0.8) 29 | #Acceso a archivos .tif: https://drive.google.com/drive/folders/1KX5c4gp1NY2M-Yi8Ztdlc7GukdsC9rU1?usp=sharing 30 | -------------------------------------------------------------------------------- /Gráficos interiores y doble eje.py: -------------------------------------------------------------------------------- 1 | #VEjemplo de crear dos gráficos en una misma ventana: 2 | plt.ion() #Nos ponemos en modo interactivo 3 | plt.subplot(1,2,1) #Una fila y dos columnas 4 | plt.plot((1,2,3,4,5)) 5 | plt.subplot(1,2,2) #Una fila y dos columnas 6 | plt.plot((5,4,3,2,1)) 7 | 8 | #Ahora daremos unas “letras” más en nuestros gráficos: 9 | plt.figure('valores por defecto') 10 | plt.suptitle('Titulo valores por defecto') 11 | plt.plot((1,2,3,4,5), label = 'por defecto') 12 | plt.legend(loc = 2) 13 | plt.rc('lines', linewidth = 2) 14 | plt.rc('font', size = 18) #Mayor tamaño desde ahora 15 | plt.figure('valores modificados') 16 | plt.suptitle('Titulo valores modificados') 17 | plt.plot((1,2,3,4,5),label = u'linea más ancha y letra más grande') 18 | plt.legend(loc = 2) 19 | 20 | #Ahora podremos embeber un área de gráfico dentro de otra: 21 | plt.ion() 22 | plt.axes() 23 | plt.plot(np.exp(np.linspace(0,10,100))) 24 | plt.axes([0.2,0.55,0.3,0.3], facecolor = 'gray') 25 | plt.plot(np.sin(np.linspace(0,10,100)), 'b-o', linewidth = 2) 26 | 27 | #Veamos ahora un gráfico de doble eje vertical: 28 | plt.ion() 29 | plt.plot(np.arange(100), 'b') 30 | plt.xlabel('Valores de x') 31 | plt.ylabel(u'Línea azul') 32 | plt.twinx() 33 | plt.plot(np.exp(np.linspace(0,5,100)), 'g') 34 | plt.ylabel(u'Línea verde') 35 | plt.xlim(-10,110) 36 | 37 | 38 | #Funciones útiles: 39 | #plt.delaxes()-> borrar el área del gráfico 40 | #plt.cla() -> borrar el contenido que hay en el área del gráfico 41 | #plt.box() -> No aparecerá la 'caja' donde se dibuja el gráfico 42 | #plt.box() -> Volverá a aparecer la 'caja‘ 43 | -------------------------------------------------------------------------------- /Evaporation calculation.py: -------------------------------------------------------------------------------- 1 | from __future__ import division 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | 5 | #generamos datos meteorológicos 6 | Rn = 150+100*np.random.rand(100) # lower bound = 150, upper boun = 250 #Radiación neta 7 | T = 25+3*np.random.randn(100) # mean = 25, std = 3 #Temperatura en grados celsius 8 | Rh = 0.2+0.6*np.random.rand(100) # lower bound = 0.2, upper boun = 0.8 # 9 | u2 = 3+np.random.randn(100) # mean = 3, std = 1 #velocidad del viento 10 | 11 | #define constants 12 | rho_w = 997; rho_a = 1.19; p = 101.1e3; z2 = 2 13 | z0 = 0.03e-2; k = 0.4; Cp = 1005 14 | 15 | #Aplicamos el método de balance energético para estimar la evaporación 16 | lv = (2500-2.36*T)*1000 # multiplicado por mil para convertir de KJ/kg a J/kg 17 | Er = 200/(lv*997) # tasa de evaporación usando el balance energético 18 | Er *= 1000*86400 # convertimos las unidades de m/s a mm/día 19 | 20 | B = 0.622*k**2*rho_a*u2/(p*rho_w*(np.log(z2/z0))**2) 21 | e_s = 611*np.exp(17.27*T/(237.3+T)) # presión de vapor de saturación 22 | e_a = Rh*e_s #presión de vapor 23 | Ea = B*(e_s-e_a) # Tasa de evaporación usando el método aerodinámico 24 | Ea *= 1000*86400 # convertimos las unidades de m/s a mm/día 25 | 26 | gamma = Cp*p/(0.622*lv) # ya que las difusividades de vapor kh/kw = 1, se simplifican en la ecuación. 27 | delta = 4098*e_s/(237.3+T)**2 #gradiente de la curva de presión de vapor de saturación 28 | w = delta/(delta+gamma) 29 | 30 | #Ahora calculamos la evaporación combinando el balance energético y método aerodinámico 31 | E = w*Er + (1-w)*Ea 32 | 33 | plt.clf() 34 | plt.subplot(2,2,1) 35 | plt.plot(Er) 36 | plt.xlabel('Time') 37 | plt.ylabel('Er') 38 | plt.subplot(2,2,2) 39 | plt.plot(Ea) 40 | plt.xlabel('Time') 41 | plt.ylabel('Ea') 42 | plt.subplot(2,2,3, facecolor='y') 43 | 44 | #Porque no usar plt.subplot(2,2,3, axisbg='y')?? pasó algo con la librería?? 45 | #revisar : https://matplotlib.org/api/_as_gen/matplotlib.pyplot.subplot.html 46 | 47 | plt.plot(E) 48 | plt.xlabel('Time') 49 | plt.ylabel('E') 50 | plt.subplot(2,2,4, facecolor='g') 51 | plt.plot(w) 52 | plt.xlabel('Time') 53 | plt.ylabel('Er/E') 54 | plt.savefig('E.png') 55 | -------------------------------------------------------------------------------- /Gráfico de lluvia.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt #importar módulo 2 | plt.plot([0,0,0,0,0,1.2,0,0,0,0,0,0,0,0,0,0,0.5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 3 | ]) #generar gráfico a partir de lista 4 | plt.xlabel('tiempo(días)', fontsize=15) #título de eje x 5 | plt.ylabel('Precipitación(mm)', fontsize=15) #título de eje y 6 | plt.grid(True) #colocar grilla ó cuadrícula 7 | plt.savefig('C:\gráficos para mi tesis\Lluvia en La Pampilla.png') #Guardar gráfico en imagen 8 | --------------------------------------------------------------------------------