How to share only the x-axis between a Curve and a Quadmesh?

Hi,

Thanks to this post, I am able to share only the x-axis between two curves:

t = np.arange(100)
data1 = np.random.rand(100)
data2 = np.random.rand(100) + 100

curve1 = hv.Curve((t, data1), 'time', 'y1')
curve2 = hv.Curve((t, data2), 'time', 'y2')

hv.Layout(curve1 + curve2)

Now I am trying to do the same between a curve and a quadmesh, but without success… The code without the x-axis shared would be the following:

t = np.arange(100)
data1 = np.random.rand(100)
data_mesh = np.random.rand(10, 100)

curve1 = hv.Curve((t, data1), 'time', 'y1')
curve2 = hv.QuadMesh((t, np.arange(10), data_mesh)) # What should I add here ?

hv.Layout(curve1 + curve2)

Any help would be very appreciated ! Thanks

They need to have the same label I think. Although you are using the same variable t, it doesn’t have an explicit label, “time”.

Maybe you can do
curve2 = ....redim.label(**{"x": "time"}) (if I correctly remember)
Or maybe

curve2 = hv.QuadMesh((t, np.arange(10), data_mesh), "time", "y2", "data")  # not sure if valid

Or use a xr.Dataset first and pass it into Curve / Quadmesh

Hi, thank you for your answer !
Unfortunetly your first guess doesn’t work, x-axis are not shared and the second one is not valid.

I got an answer from stackoverflow here that works. The idea is very close to yours ! The working code is the following:

import numpy as np, holoviews as hv
hv.extension("bokeh")

t = np.arange(100)
data1 = np.random.rand(100)
data_mesh = np.random.rand(10, 100)

curve1 = hv.Curve((t, data1), 'time', 'y1')
curve2 = hv.QuadMesh((t, np.arange(10), data_mesh)).redim(x='time')

curve1 + curve2
1 Like