Ben Chuanlong Du's Blog

It is never too late to learn.

Interactive Tools of Plots in HoloViews

In [40]:
import numpy as np
import pandas as pd
import holoviews as hv

hv.extension("bokeh")
In [45]:
%%opts Points [size_index='z' width=600, height=500 tools=['hover']] HeatMap [toolbar='above' tools=['hover']]
points = hv.Points([(chr(i+65), chr(j+65), i*j) for i in range(10) for j in range(10)], vdims='z')
hv.HeatMap(points) * points
Out[45]:
In [42]:
macro_df = pd.read_csv("http://assets.holoviews.org/macro.csv", "\t")
key_dimensions = [("year", "Year"), ("country", "Country")]
value_dimensions = [
    ("unem", "Unemployment"),
    ("capmob", "Capital Mobility"),
    ("gdp", "GDP Growth"),
    ("trade", "Trade"),
]
macro = hv.Table(macro_df, key_dimensions, value_dimensions)
In [43]:
%%opts Overlay [width=700 height=400 show_frame=False]
%%opts Curve [tools=['hover']] Scatter [color_index=2 size_index=2 scaling_factor=1.4] (cmap='Blues' line_color='k')
%%opts VLine (color='k' line_width=1)
%%opts Text (text_font_size='13px')
In [44]:
gdp_curves = macro.to.curve("Year", "GDP Growth")
gdp_unem_scatter = macro.to.scatter("Year", ["GDP Growth", "Unemployment"])
annotations = (
    hv.Arrow(1973, 8, "Oil Crisis", "v")
    * hv.Arrow(1975, 6, "Stagflation", "v")
    * hv.Arrow(1979, 8, "Energy Crisis", "v")
    * hv.Arrow(1981.9, 5, "Early Eighties\n Recession", "v")
)
gdp_curves * gdp_unem_scatter * annotations
Out[44]:

Comments