Search code examples
pythonbokehholoviews

Removing background color in holoviews image


What is the correct way to specify the background colour for a Holoviews image? Here's the example I am using:

import holoviews as hv
import numpy as np
hv.extension('bokeh')
eye = np.eye(10)
hv.Image(eye).opts(clipping_colors={0: 'red'})

I also tried defining clipping_colors with other values like NaN or "0", but they all give a faint blue background color as in the attached image. holoviews background color


Solution

  • The background color is specified like .opts(bgcolor=<color>), but note that the background will only show for missing pixels, and eye here is a dense array, with no NaN values. If you want zero to be treated like missing value, then you can specify that:

    import holoviews as hv
    import numpy as np
    hv.extension('bokeh')
    eye = np.eye(10)
    hv.Image(eye).opts(bgcolor="red").redim.nodata(z=0)
    

    eye matrix with red bg