Problem setting default global colormap

I’m using hvplot with xarray in JupyterLab to plot 2d DataArrays. I have been trying to set some global parameters using the following commands in the first cell of the notebook

import hvplot.xarray
from holoviews import opts
customrainbow = [ '#000000', '#040003', '#090007', '#0d000a', '#12000e', ... ]
opts.defaults(opts.Image(aspect="square", cmap=customrainbow, toolbar="above"))

and in the next cell of the notebook I plot a DataArray called array using


When I plot the DataArray, the two settings aspect=“square” and toolbar=“above” are correctly applied, but the cmap option is not (it is always what I believe to be bokeh “blues”). I have tried changing to various other default colormaps instead of my custom colormap with the same result. If I put the cmap directly inside the plot command as


everything works fine. Does anyone have any idea why this might be happening? Is there a problem with my code, or could this be a bug? Thanks!

Package versions:

hvPlot defines it’s own custom cmaps to more closely match the defaults of the plotting APIs its emulating (i.e. pandas and xarray defaults) and also to automatically switch between numeric and categorical colormaps. There should however be a documented way of controlling hvPlot defaults more easily.

Thanks for the information. Is there any way to do what I’m trying to do, or is it necessary at the moment to keep specifying my custom color map in every call to hvplot()?

Does anyone know anything more about this? I know it’s not the most important issue, but it would be useful not to have to specify the custom colormap every time hvplot is called.

I have this problem as well. I don’t understand why some global opts work while colormap doesn’t, isn’t that inconsistent?

It’s unfortunate that hvPlot is not able to use HoloViews’s options defaults, but I don’t know of any current way around this. The HoloViews defaults should be respected already for anything that hvPlot is not trying to do itself already, but hvPlot has to handle colormaps internally to get behavior to match Matplotlib-based .plot() output, so it overrides the HoloViews defaults in those cases. It would be great to add code to hvPlot to detect when the HoloViews default has been changed and use that rather than its own handling, but I don’t know how difficult that would be, and I don’t think anyone is currently working on that. It’s definitely inconsistent from a user perspective, but from a HoloViews perspective, hvPlot is user code, and if the user (hvPlot in this case) says to use a certain colormap, HoloVIews will ignore the overall default as instructed, so the HoloViews default won’t have any effect when used with hvPlot (unless we can hack that in somewhere).