pydata / xarray

N-D labeled arrays and datasets in Python
https://xarray.dev
Apache License 2.0
3.61k stars 1.08k forks source link

Transform not working with xlim / ylim and col_wrap #8562

Closed sarahclaude closed 10 months ago

sarahclaude commented 10 months ago

What happened?

I get back the wrong projections when passing transform with col_wrap = 2 while plotting a facetgrid (first picture). I also get empty subplots when using transform = ccrs.PlateCarrree with a defined xlim and ylim (second picture).

image image

What did you expect to happen?

image

Minimal Complete Verifiable Example

import xarray as xr

url = 'https://pavics.ouranos.ca//twitcher/ows/proxy/thredds/dodsC/birdhouse/disk2/cccs_portal/indices/Final/BCCAQv2_CMIP6/tx_max/YS/ssp585/ensemble_percentiles/tx_max_ann_BCCAQ2v2+ANUSPLIN300_historical+ssp585_1950-2100_30ymean_percentiles.nc'

opened = xr.open_dataset(url, decode_timedelta=False)
ds_space = opened[['tx_max_p50']].isel(time=[0, 1, 2]).sel(lat=slice(40,65), lon=slice(-90,-55))

#transform with col_wrap
ds_space['tx_max_p50'].plot(**{"x": "lon", "y": "lat", "col": "time", 'col_wrap':2},
                            subplot_kws={"projection": ccrs.LambertConformal()},
                            transform = ccrs.PlateCarree()
                           )

#transform and xlim/ylim
ds_space['tx_max_p50'].plot(**{"x": "lon", "y": "lat", "col": "time", 
"xlim": [-70, -75], "ylim": [45, 50]},
                            subplot_kws={"projection": ccrs.LambertConformal()},
                            transform = ccrs.PlateCarree()
                           )

MVCE confirmation

Relevant log output

No response

Anything else we need to know?

No response

Environment

commit: None python: 3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:27:40) [GCC 11.3.0] python-bits: 64 OS: Linux OS-release: 6.2.0-39-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: fr_CA.UTF-8 LOCALE: ('fr_CA', 'UTF-8') libhdf5: 1.14.0 libnetcdf: 4.9.2 xarray: 2023.10.1 pandas: 2.0.2 numpy: 1.24.3 scipy: 1.10.1 netCDF4: 1.6.4 pydap: None h5netcdf: None h5py: 3.8.0 Nio: None zarr: 2.15.0 cftime: 1.6.2 nc_time_axis: None PseudoNetCDF: None iris: None bottleneck: 1.3.7 dask: 2023.6.0 distributed: 2023.6.0 matplotlib: 3.7.1 cartopy: 0.21.1 seaborn: 0.12.2 numbagg: None fsspec: 2023.6.0 cupy: None pint: 0.22 sparse: None flox: None numpy_groupies: None setuptools: 67.7.2 pip: 23.1.2 conda: None pytest: 7.3.2 mypy: None IPython: 8.14.0 sphinx: 7.0.1
welcome[bot] commented 10 months ago

Thanks for opening your first issue here at xarray! Be sure to follow the issue template! If you have an idea for a solution, we would really welcome a Pull Request with proposed changes. See the Contributing Guide for more. It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better. Thank you!