-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxarray_ejemplo2.py
More file actions
56 lines (47 loc) · 1.58 KB
/
xarray_ejemplo2.py
File metadata and controls
56 lines (47 loc) · 1.58 KB
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
import xarray as xr
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from glob import glob
ncfiles = glob('*.nc')
first = True
for nc in ncfiles:
if first:
ds_all = xr.open_dataset(nc)
first = False
else:
ds = xr.open_dataset(nc)
ds_all = xr.concat([ds_all,ds], dim='time')
figsetup = dict(cmap='RdBu',vmin=0,vmax=50,extend='neither')
scale=0.7
figsetup['figsize'] = (10*scale,10*scale)
figsetup['x'] = 'lons'
figsetup['y'] = 'lats'
figsetup['col'] = 'time' # <- faceting
figsetup['col_wrap'] = 2
figsetup['transform'] = ccrs.PlateCarree()
figsetup['subplot_kws'] = {'projection': ccrs.PlateCarree()}
plot_handle = ds_all.pwat.plot(**figsetup);
# opciones para la grilla
gl_setup = dict(crs=ccrs.PlateCarree(),
draw_labels=False,
linewidth=2,
color='gray',
alpha=0.5,
linestyle='--')
for n, ax in enumerate(plot_handle.axes.flat): # <- enumerate
ax.add_feature(cartopy.feature.BORDERS)
ax.add_feature(cartopy.feature.COASTLINE)
ax.set_extent([-100, -65, -45, -15]) # utilizar extent en lugar de xlim/ylim
ax.set_aspect('equal','box-forced') # <- obligatorio
# formato de grilla lat/lon
gl = ax.gridlines(**gl_setup)
if n in [0,2]:
gl.ylabels_left = True
elif n == 4:
gl.xlabels_bottom = True
gl.ylabels_left = True
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
plt.show()