简体   繁体   中英

Is there a way to reduce the resolution of xarray facetgrid plots?

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?

eg, 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.

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, eg:

# 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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM