Search code examples
pythonjupyterbokehholoviews

Linking x y axes but not colorbars in HoloViews subplots


I need Holoviews/bokeh heatmap subplots with shared xy-axes but independent colorbars. The following creates subplots with correctly linked xy-axes, but since the z-data ranges are strongly different, the colorbar linkage makes the plot on the right useless:

import holoviews as hv
import numpy as np
hv.extension('bokeh')

X, Y = np.meshgrid(np.linspace(-1, 1, 101), np.linspace(-2, 2, 201))
Z1 = X ** 2 + Y ** 2
Z2 = 0.2 * np.sin(X + 100) + 0.1 * np.cos(Y * 10)

props_subplots = [(Z1, "viridis", "Z1"), 
                  (Z2, "Greens_r", "Z2")]

hv.Layout([hv.HeatMap((X, Y, data)).opts(frame_width=200, colorbar=True, cmap=cmap, title=title) 
           for data, cmap, title in props_subplots]).opts(shared_axes=True)

enter image description here


In contrast, setting shared_axes=False gives the desired output, but obviously, x and y are also independent now.

enter image description here


How can we link x and y while letting the colorbars scale automatically and independently?


Solution

  • Found here:

    The problem is, that the value dimensions in all subplots have the same name and are thus included in the axes sharing. If we name the Z-dimension differently in each subplot (vdims=[title]), colorbars will not be linked, despite shared_axes=True:

    ...
    
    hv.Layout([hv.HeatMap((X, Y, data), ["x", "y"], [title])
                     .opts(frame_width=200, colorbar=True, cmap=cmap, title=title) 
               for data, cmap, title in props_subplots]).opts(shared_axes=True)