Reputation: 111
When plotting a single xarray I can use something like: ds['variable'][::5,::5].plot()
to reduce the lat and lon resolution by a factor of 5. Is there a similar way to reduce the resolution when using facet grids?
e.g., I'm currently plotting: WL_monthly.plot(x='lon',y='lat',col='time',col_wrap=4)
but due to the high resoultion of the data it takes a couple of minutes to plot.
I tried: WL_monthly[::5,::5].plot(x='lon',y='lat',col='time',col_wrap=4)
but this slices the array's time entries.
Upvotes: 1
Views: 251
Reputation: 15452
When slicing positionally like this, the slice arguments are interpreted in the order of the array's dimensions. So you can inspect WL_monthly.dims
to see the dimension ordering and then slice accordingly.
For example, if your array has dimensions (time, lat, lon)
, you could plot using:
WL_monthly[:, ::5,::5].plot(x='lon',y='lat',col='time',col_wrap=4)
You can also slice using named dimensions using .sel
or using .loc
, which allows you to specify dims using a dictionary and slice with a python slice
object, e.g.:
# using .sel()
WL_monthly.sel(lat=slice(None, None, 5), lon=slice(None, None, 5))
# using .loc[]
WL_monthly.loc[{'lat': slice(None, None, 5), 'lon': slice(None, None, 5)}]
This is admittedly a bit clunky. The xarray docs on indexing and selecting data summarize the situation well:
We would love to be able to do indexing with labeled dimension names inside brackets, but unfortunately, Python does yet not support indexing with keyword arguments like
da[space=0]
Upvotes: 1