Skip to content

specifying list of colors does not work for me #3284

@mathause

Description

@mathause

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions