0

I'm plotting a heatmap with holoviews using the Plotly backend.

import holoviews as hv

hv.HeatMap([(0,0,-10),(0,1,-9),(1,0,0),(1,1,2)]).opts(cmap="RdBu")

I'd like to set the colormap midpoint to 0 to make the diverging colormap meaningful. In plotly I would do color_continuous_midpoint=0 for the px.imshow function of plotly express.

How can I set the colormap midpoint in holoviews?

Does Holoviews use px.imshow? If so, is there a way to pass through this (or any) raw parameters? How can I find the solution in the documentation of Holoviews? I tried, but failed to find a hint.

Gere
  • 12,075
  • 18
  • 62
  • 94
  • HoloViews is built on Plotly, not Plotly Express; its Plotly support predated Plotly Express. I'm not aware of any convenient way to set the midpoint, so that would be a good feature request. – James A. Bednar Nov 18 '21 at 19:56

1 Answers1

0

You can set the midpoint indirectly by specifying the limits of the colormap via the clim parameter. E.g. the following has a midpoint of 0:

hm = hv.HeatMap(data)
hm.opts(colorbar=True, cmap="coolwarm_r", clim=(-30, 30))

From the docs:

clim: User-specified colorbar axis range limits for the plot, as a tuple (low,high). If specified, takes precedence over data and dimension ranges.

Also check out the clim_percentile parameter:

clim_percentile: Percentile value to compute colorscale robust to outliers. If True, uses 2nd and 98th percentile; otherwise uses the specified numerical percentile value.

fischja
  • 51
  • 6