In [ ]:
import pandas as pd
import holoviews as hv
from holoviews import opts

from holoviews.plotting.links import RangeToolLink

hv.extension('bokeh')

This demo demonstrates how to link two timeseries plots using the RangeToolLink along the x-axis. This can be useful to get an overview and a detailed view of some data at the same time.

Declare data


In [ ]:
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 ($)'))

Declare plot

Having declared a Curve element containing the AAPL stock closing prices we create two copies of it with different styling. One smaller view which will become the source of the link which will display the range tool, and a larger target view whose axes will be linked to the range of the RangeTool on the source:


In [ ]:
tgt = aapl_curve.relabel('AAPL close price').opts(width=800, labelled=['y'], toolbar='disable')
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))