Keyed color map for image?

How do you specify color maps for categorical (e.g. string) data?

import xarray as xr
import hvplot.xarray

da = xr.DataArray([["a", "b"],["b", "b"]], dims=("x", "y"))

This yields an error TypeError: unsupported operand type(s) for -=: 'str' and 'float', but I suspect one is somehow able to map the values to colors? I hoped to specify a color_key={"a": "#ffffff", "b": "#000000"} (which seems to be an option for datashader), but the argument is not recognized. Is there a different approach?

HoloViews supports providing a dictionary as a cmap:

da.hvplot.image(cmap={"a": "#ffffff", "b": "#000000"})

If you want to make an issue to make color_key an alias for cmap in the categorical case that would be appreciated.

Thanks! I feel I have to explain why I didn’t figure that out on my own. My actual data is integers, and the cmap argument did not work in that case (no error, the Image simply won’t display, see But I have no problem converting to strings!