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

specifying list of colors does not work for me #3284

Closed
mathause opened this issue Sep 6, 2019 · 1 comment · Fixed by #3295
Closed

specifying list of colors does not work for me #3284

mathause opened this issue Sep 6, 2019 · 1 comment · Fixed by #3295

Comments

@mathause
Copy link
Collaborator

mathause commented Sep 6, 2019

MCVE Code Sample

import xarray as xr
import numpy as np

airtemps = xr.tutorial.load_dataset('air_temperature')

air = airtemps.air.isel(time=0)


levels = np.arange(225, 301, 25)

colors = ['#ffffb2', '#fecc5c', '#fd8d3c', '#e31a1c']

# this does not work for me
air.plot.pcolormesh(levels=levels, colors=colors)

Expected Output

Should create a plot with the specified colors. According to the the docstring this should work. Or maybe I am doing something wrong here?

Problem Description

Instead I get the following error:

/usr/local/Miniconda3-envs/envs/2019/envs/iacpy3_2019/lib/python3.7/site-packages/xarray/plot/utils.py in _process_cmap_cbar_kwargs(func, kwargs, data)
    683     # colors is only valid when levels is supplied or the plot is of type
    684     # contour or contourf
--> 685     if colors and (('contour' not in func.__name__) and (not levels)):
    686         raise ValueError("Can only specify colors with contour or levels")
    687 

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Instead I use the following, which works:

air.plot.pcolormesh(levels=levels, cmap=colors)

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.7.1 | packaged by conda-forge | (default, Feb 18 2019, 01:42:00) [GCC 7.3.0] python-bits: 64 OS: Linux OS-release: 4.12.14-lp151.28.13-default machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.4 libnetcdf: 4.6.2

xarray: 0.12.1
pandas: 0.24.2
numpy: 1.16.2
scipy: 1.2.1
netCDF4: 1.5.0.1
pydap: installed
h5netcdf: 0.7.1
h5py: 2.9.0
Nio: None
zarr: 2.3.1
cftime: 1.0.3.4
nc_time_axis: 1.2.0
PseudonetCDF: None
rasterio: 1.0.22
cfgrib: 0.9.7
iris: 2.2.0
bottleneck: 1.2.1
dask: 1.1.5
distributed: 1.26.1
matplotlib: 3.0.3
cartopy: 0.17.0
seaborn: 0.9.0
setuptools: 41.0.0
pip: 19.0.3
conda: None
pytest: 4.4.0
IPython: 7.4.0
sphinx: 2.0.1

@mathause
Copy link
Collaborator Author

mathause commented Sep 9, 2019

I just found out - the error actually comes from using a numpy array to the define the levels (and (not levels)) and not from using colors. So it is in a way a user error. However, I suppose it would be good to support numpy arrays to pass levels?

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

Successfully merging a pull request may close this issue.

1 participant