I would like to realize a holoviews plot with a scrollbar for the time/x axis.
In detail, I want to plot a long ecg signal (20 minutes) and be able to display a frame of e.g. 10 seconds with the possibility to scroll along the entire signal.
Is there a way to realize this? Thank you!
There are at least two options you should know about.
1. Option
Enable the scrolling by mouse.
For this you have to activate the tool xwheel_pan
for your figure.
See this very basic example:
import numpy as np
import holoviews as hv
hv.extension('bokeh')
x = np.linspace(0, 4*np.pi, 100)
y = np.sin(x)
scatter = hv.Scatter((x, y), label='sin(x)').opts(
tools=['xwheel_pan'],
active_tools=['xwheel_pan']
)
scatter
In this example the tool is also activated by default. Using the wheel of the mouse will result in an action like this.
2. Option
Add a second figure and a RangeTool
.
This example needs some more lines of code:
import numpy as np
import holoviews as hv
from holoviews import opts
from holoviews.plotting.links import RangeToolLink
hv.extension('bokeh')
x = np.linspace(0, 4*np.pi, 100)
y = np.sin(x)
scatter = hv.Scatter((x, y), label='sin(x)').opts(width=300, height=300)
selection = hv.Scatter((x, y)).opts(width=300, height=100, yaxis=None, default_tools=[])
RangeToolLink(selection, scatter)
layout = (scatter + selection).cols(1)
layout.opts(opts.Layout(shared_axes=False, merge_tools=False))