Timeseries Range Tool#

Download this notebook from GitHub (right-click to download).


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#

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:

tgt = aapl_curve.relabel('AAPL close price').opts(width=800, height=300, 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))

Specify initial bounds#

Use the boundsx and boundsy parameters to specify the initial range of the RangeTool:

from datetime import datetime

tgt = aapl_curve.relabel('AAPL close price').opts(width=800, height=300, labelled=['y'], toolbar='disable')
src = aapl_curve.opts(width=800, height=100, yaxis=None, default_tools=[])

RangeToolLink(src, tgt, axes=['x', 'y'], boundsx=(datetime(2006, 1, 1) , datetime(2010, 1, 1)), boundsy=(None, 400))

layout = (tgt + src).cols(1)
layout.opts(opts.Layout(shared_axes=False, merge_tools=False))
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Download this notebook from GitHub (right-click to download).