Reputation: 25
Is there a way to adjust the selection range in the RangeToolLink?
By default, the entire area of the plot is selected, which can then be adjusted and/or moved accordingly.
(From https://www.holoviews.org/gallery/demos/bokeh/timeseries_range_tool.html)
Upvotes: 0
Views: 82
Reputation: 111
You actually don't need to set the range hook on the rangetool element, just the data curve plot
import pandas as pd
import holoviews as hv
from holoviews import opts
from holoviews.plotting.links import RangeToolLink
hv.extension('bokeh')
from bokeh.sampledata.stocks import AAPL
aapl_df = pd.DataFrame(AAPL['close'], columns=['close'], index=pd.to_datetime(AAPL['date']))
aapl_df.index.name = 'Date'
aapl_curve = hv.Curve(aapl_df, 'Date', ('close', 'Price ($)'))
def hook(plot, element):
plot.handles['x_range'].start = pd.to_datetime('2006')
plot.handles['x_range'].end = pd.to_datetime('2008')
tgt = aapl_curve.relabel('AAPL close price').opts(width=800, labelled=['y'], toolbar='disable').opts(hooks=[hook])
src = aapl_curve.opts(width=800, height=100, yaxis=None, default_tools=[])
RangeToolLink(src, tgt)
layout = (tgt + src).cols(1)
layout.opts(opts.Layout(shared_axes=False, merge_tools=False))
Upvotes: 1
Reputation: 6347
In Holoviews it is possible to set the underling properties of the figure using a hook.
In the example below there are two different hooks used for the upper and lower figure.
import pandas as pd
import holoviews as hv
from holoviews import opts
from holoviews.plotting.links import RangeToolLink
hv.extension('bokeh')
from bokeh.sampledata.stocks import AAPL
aapl_df = pd.DataFrame(AAPL['close'], columns=['close'], index=pd.to_datetime(AAPL['date']))
aapl_df.index.name = 'Date'
aapl_curve = hv.Curve(aapl_df, 'Date', ('close', 'Price ($)'))
def hook(plot, element):
plot.handles['x_range'].start = pd.to_datetime('2006')
plot.handles['x_range'].end = pd.to_datetime('2008')
tgt = aapl_curve.relabel('AAPL close price').opts(width=800, labelled=['y'], toolbar='disable').opts(hooks=[hook])
def hook(plot, element):
plot.handles['x_range'].start = pd.to_datetime('2000')
plot.handles['x_range'].end = pd.to_datetime('2014')
src = aapl_curve.opts(width=800, height=100, yaxis=None, default_tools=[]).opts(hooks=[hook])
RangeToolLink(src, tgt)
layout = (tgt + src).cols(1)
layout.opts(opts.Layout(shared_axes=False, merge_tools=False))
The result is very similar to the range_tool example of the bokeh library.
Upvotes: 3