Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facetgrid: colors beyond range (extend) not saturated #2932

Closed
lvankampenhout opened this issue Apr 30, 2019 · 5 comments · Fixed by #2935
Closed

Facetgrid: colors beyond range (extend) not saturated #2932

lvankampenhout opened this issue Apr 30, 2019 · 5 comments · Fixed by #2935

Comments

@lvankampenhout
Copy link

lvankampenhout commented Apr 30, 2019

Code Sample, a copy-pastable example if possible

Screen Shot 2019-04-30 at 11 59 30

Minimal example here:
https://github.com/lvankampenhout/bug-reports/blob/master/Facetgrid_cmap_extend.ipynb

Problem description

The extreme colors of neither the pcolormesh or colorbar (using extend='both') are not saturated as they should when faceting.

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.8 |Anaconda custom (x86_64)| (default, Dec 29 2018, 19:04:46) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] python-bits: 64 OS: Darwin OS-release: 17.7.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: C LANG: None LOCALE: None.None libhdf5: 1.10.1 libnetcdf: 4.4.1.1

xarray: 0.12.1
pandas: 0.23.4
numpy: 1.14.2
scipy: 0.18.1
netCDF4: 1.3.1
pydap: None
h5netcdf: None
h5py: 2.7.1
Nio: None
zarr: None
cftime: 1.0.0b1
nc_time_axis: None
PseudonetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.2.0
dask: 0.13.0
distributed: None
matplotlib: 3.0.2
cartopy: 0.16.0
seaborn: 0.7.1
setuptools: 38.5.1
pip: 9.0.1
conda: 4.6.14
pytest: 3.0.5
IPython: 5.1.0
sphinx: 1.5.1

@mathause
Copy link
Collaborator

mathause commented Apr 30, 2019

For completeness I add the minimal example

%matplotlib

import numpy as np; import xarray as xr
da = xr.tutorial.open_dataset('air_temperature').air
cmap = 'RdBu_r'
levels = np.arange(240,300+1,10)
da.isel(time=slice(4)).plot(cmap=cmap, col='time', levels=levels, extend='both')

What I think happens is that the cmap is determined twice. First in facetgrid.py. This returns a matplotlib.colors.ListedColormap with 6 colors. Then this reduced colormap is used in plot.py. However, now it only has 6 colors to choose from, so the _over and _under colors are the same as the first and last color.

@mathause
Copy link
Collaborator

The easiest way to fix this is probably to reset the cmap in facetgrid.py Lines 224-227

cmap = kwargs.get('cmap', None)

cmap_params, cbar_kwargs = _process_cmap_cbar_kwargs(func, kwargs, self.data.values)

# reset the colormap #GH2932
cmap_params['cmap'] = cmap

@lvankampenhout
Copy link
Author

Thanks, I've implemented your suggestion as a workaround, but it fails with the following error:

NameError: name '_process_cmap_cbar_kwargs' is not defined

@dcherian
Copy link
Contributor

See #3038

@dcherian
Copy link
Contributor

Seems to work now? probably fixed by #3601

7cfd12224bfde93bb1a8192bb4e9c2a82ab6f9a5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants