1

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

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... I have seen Share x-axis between Bokeh plots but it uses only the bokeh api and I would like to use holoviews.

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)

I tried some options, such as relabel the x-axis but without success. How should I do ?

Any help would be very appreciated ! Thanks

etiennedm
  • 409
  • 1
  • 3
  • 9

1 Answers1

1

In HoloViews, axes are shared if they are considered to have the same Dimension. Dimensions are considered the same if they have the same name and (optional) label, so simply changing the label is not enough to make it match a Dimension on another plot with a different name. See the user guide for the details, but here you can change the QuadMesh to declare that its x dimension is the same as the one from the Curve.

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

plot

James A. Bednar
  • 3,195
  • 1
  • 9
  • 13
  • Thank you so much ! I saw the user guide but could not find the right parameter for `.redim()`... I tried `.redim(kdims=['time', 'y2'])` without success, but yours works ! If you know where the doc is that would be awesome. In any case, thank you ! – etiennedm Feb 04 '22 at 08:36
  • Yeah, I don't know where it's documented that the default dimensions for an image are "x" and "y", nor do I know how to declare the original kdims to be 'time','y2'; I just always do it this way and it works. Once you get comfortable with this and can see a good place to add this info in the docs, please make a PR to improve it for the next person! – James A. Bednar Feb 05 '22 at 04:10