Advertisement
Guest User

contour

a guest
Oct 17th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. import numpy as np
  2. from scipy.interpolate import griddata
  3. import matplotlib.pyplot as plt
  4.  
  5. levels = range(-200, -80, 30)
  6. lon = (-73.2898, -73.8519)
  7. lat = (6.767, 7.3601)
  8.  
  9. datos_contorno = {'Z': [[7.3601, -73.8519, -117.45652173913044], [7.1269, -73.2898, -129.97826086956522], [6.767, -73.725, -130.21014492753622]]}
  10.  
  11. contador = 1
  12. banda = datos_contorno["Z"]
  13. if len(banda[0]) > 2:  # mas de dos estaciones
  14.     print("por aca pasó")
  15.     traspuesta = [list(f) for f in (zip(*banda))]
  16.     # coordenadas de datos y valores
  17.     x = np.array(traspuesta[0])
  18.     y = np.array(traspuesta[1])
  19.     z = np.array(traspuesta[2])
  20.  
  21.     # cuadrícula de destino a interpolar
  22.     xi = np.linspace(lon[1], lon[0], 12)
  23.     yi = np.linspace(lat[0], lat[1], 12)
  24.     xi, yi = np.meshgrid(xi, yi)
  25.  
  26.     # interpolar
  27.     zi = griddata((x, y), z, (xi, yi), method="linear")
  28.     print(zi)
  29.     # plotear
  30.     fig = plt.figure()
  31.     ax = fig.add_subplot(111)
  32.     cs = plt.contourf(xi, yi, zi, levels=levels)
  33.  
  34.     plt.contour(cs, colors='k')
  35.     plt.xlabel('Longitud', fontsize=16)
  36.     plt.ylabel('Latitud', fontsize=16)
  37.     plt.colorbar()
  38.     plt.scatter(x, y, marker='o', c='b', s=5)
  39.     plt.grid()
  40.     plt.savefig("fig_" + str(contador) + '.png')
  41.     plt.close(fig)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement