How to link the axis in multiple holoviews plots?
Asked Answered
S

1

6

I have created to datashader plots with holoviews:

datashade(hv.Points(df[
    [
        'PS Engine-% Load', 
        'PS Engine-Fuel Rate',
    ]
])) + datashade(hv.Points(df[
    [
        'SB Engine-% Load', 
        'SB Engine-Fuel Rate',
    ]
]))

Both graphs are plotted fine, now I want to link the ranges of the axis so when I zoom in one graph the other graph is also zoomed in the same way. From what I understand normally axis are linked when the source values are the same. In this case the sources for both the X and Y axis are different (note the PS and SB values) but the ranges are the same. How can I link these axis?

Snigger answered 31/8, 2017 at 11:58 Comment(0)
G
5

Yes, HoloViews will automatically link dimensions that it considers to be "the same", where "the same" comes down to having the same name and unit. In this case, probably the easiest thing to do is to make sure the dimensions you want to link have the same column name in the dataframe:

df_ps = df.rename(columns={'PS Engine-% Load': '% Load'})
df_sb = df.rename(columns={'SB Engine-% Load': '% Load'})
datashade(hv.Points(df_ps[['% Load','PS Engine-Fuel Rate']])) + \
datashade(hv.Points(df_sb[['% Load','SB Engine-Fuel Rate']]))

If the Fuel Rate should also be linked, just add that to the rename dictionary for each one as well. Example before zooming:

Without zooming in

and after zooming in:

After zooming in

Gerlac answered 3/9, 2017 at 14:10 Comment(3)
Except one thing :( When I zoom in the graph is not redrawn so the pixels get bigger when zooming in. As soon as a revert to the old method the graph is redrawn again. What could cause this?Snigger
Not sure; I expanded the answer to include an example of doing this, and as you can see, the axes are linked and the datashader plot refreshes. If you try this and still have problems, there are probably errors listed on your JS console (search the web to see how to open that for your browser).Gerlac
The problem of not updating the picture when zooming was caused by the '%%output size=200' option in the cell. After removing that everything worked as expected. I'll try to find a solution for that, but that's another problem.Snigger

© 2022 - 2024 — McMap. All rights reserved.