pythonbokehholoviewsdatashaderpyviz

Prevent the colormap to be rescaled when using datashader to rerender an image as it is zoomed in


I want to use datashader's automatic downsampling and rerendering upon zoom to display large images. Reading the docs and forums for holoviews, bokeh, and datashader, it is my understanding that it is preferable to do this via Holoviews instead of directly with datashader and bokeh (let me know if this is not the case).

The code below is working great for redrawing the image resolution when zooming and is much faster than rendering the full images. However, I can't seem to figure out how to avoid rescaling the colormap range as the image zooms. For example, zooming in to one of the black regions will eventually render it as bright when none of the high intensity regions are within view.

I would like to have the colormap range fixed as the min and max (or close to these values, ideally I would have the same control as with vmin and vmax in matplotlib) of the entire array/image and not update as the image is zoomed in. I don't see any parameter controlling this in either regrid or hv.Image, is it possible to achieve?

import holoviews as hv
from holoviews.operation.datashader import regrid
from skimage import data


hv.extension('bokeh')

im = data.coins()
hv_im = hv.Image(im).opts(active_tools=['wheel_zoom'])
regrid(hv_im)

I also tried using datashade instead of regrid, but the results were similar.


Solution

  • I found my answer in this comment from 2017 on the Holoviews issue tracker. The following works

    regrid(hv_im).opts(clim=(im.min(), im.max()))
    

    I tried looking through the docs again to see if it was mentioned somewhere. Did not find anything in the search other than a brief mention in the FAQ.