-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_dataw_nc.py
78 lines (70 loc) · 1.62 KB
/
plot_dataw_nc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from netCDF4 import Dataset
from matplotlib import pyplot as plt
import cartopy.crs as ccrs
import cartopy.vector_transform as cvt
from sys import argv
filename = argv[1]
print(filename)
root=Dataset(filename, 'r')
#define proyeccion
proj = ccrs.PlateCarree()
#lee datos
T2 = root.variables['T2'][12]
lat = root.variables['lat'][:]
lon = root.variables['lon'][:]
u = root.variables['U10'][:][12]
v = root.variables['V10'][:][12]
x,y,u,v=cvt.vector_scalar_to_grid(proj, proj,
10,
lon,
lat,
u,
v,
)
#wplot=ax.streamplot(
# data['lonc'],
# data['latc'],
# u,v,
# #linewidth=1,
# #density=2,
# color='red',
# #cmap=plt.cm.tab10,
# #levels=np.arange(0,2,0.2),
# zorder=5,
# )
#obtiene limites
latmin = lat[0, 0]
latmax = lat[-1, 0]
lonmin = lon[0, 0]
lonmax = lon[0, -1]
plt.figure()
ax_lim= [lonmin, lonmax, latmin, latmax]
ax = plt.axes(projection= proj)
ax.set_extent(ax_lim, proj)
#dibuja grid
ax.gridlines(draw_labels=["top", "right"], dms=True, x_inline=False, y_inline=False)
#dibuja lineas de costa
ax.coastlines()
# graficacion de variable
var_map = plt.contourf(lon, lat, T2, transform= proj )
#color bar
cbar=plt.colorbar(
var_map,
#ax=ax,
#shrink=0.75,
orientation='horizontal',
aspect=50,
pad=0.02,
fraction=0.03,
)
cbar.ax.set_xlabel('Variable')
ax.barbs(
x,y,u,v,
#sizes=dict(emptybarb=0.1, spacing=2.2, height=0.5),
#linewidth=0.95,
#length=10,
#pivot='middle',
#transform=ccrs.PlateCarree(),
zorder=25,
)
plt.savefig('figure_nc.png')