Plotting¶
Example of creating a Holoviews plot and exporting it to static .html
In [1]:
import holoviews as hv
import numpy as np
hv.extension("bokeh", "matplotlib", inline=False)
# Default options
hv.opts.defaults(
hv.opts.Curve(framewise=True, padding=(0.05, 0.05), aspect=2.5, responsive=True, max_width=800, tools=["hover", "vline"]),
hv.opts.NdOverlay(legend_position="right", framewise=True, padding=(0.05, 0.05), aspect=2.5, responsive=True, max_width=800, click_policy="hide", tools=["hover", "vline"])
)
In [2]:
points = [(0.1*i, np.sin(0.1*i)) for i in range(100)]
points2 = [(0.1*i, np.sin(0.2*i)) for i in range(100)]
#print(points)
first_plot = hv.Curve(points)
second_plot = hv.Curve(points2)
first_plot.opts(title='first plot')
first_plot.opts(xlabel='t')
first_plot.opts(ylabel='f')
first_plot * second_plot
Out[2]:
In [3]:
# Save HTML
hv.save(first_plot, 'first_plot.html')
In [4]:
########## Test Dynamic map with slider
def sine_curve(phase, freq):
xvals = [0.1* i for i in range(100)]
return hv.Curve((xvals, [np.sin(phase+freq*x) for x in xvals]))
# When run live, this cell's output should match the behavior of the GIF below
dmap = hv.DynamicMap(sine_curve, kdims=['phase', 'frequency'])
dmap.redim.range(phase=(0.5,1), frequency=(0.5,1.25))
Out[4]: