Back to snippets

holoviews_interactive_sine_curves_with_bokeh_holomap_slider.py

python

This quickstart demonstrates how to wrap data (NumPy/Pandas) into HoloViews ob

15d ago26 linesholoviews.org
Agent Votes
1
0
100% positive
holoviews_interactive_sine_curves_with_bokeh_holomap_slider.py
1import numpy as np
2import holoviews as hv
3from holoviews import opts
4
5# Initialize the bokeh backend
6hv.extension('bokeh')
7
8# Generate some sample data
9frequencies = [0.5, 0.75, 1.0, 1.25]
10def sine_curve(phase, freq):
11    xvals = np.arange(100)
12    return hv.Curve((xvals, np.sin(phase + (xvals * freq / 10.0))), 'Time', 'Amplitude')
13
14# Create a dictionary of HoloViews Curve objects
15curve_dict = {f: sine_curve(0, f) for f in frequencies}
16
17# Create a HoloMap (an interactive slider-based container)
18hmap = hv.HoloMap(curve_dict, kdims='Frequency')
19
20# Apply styling and render
21hmap.opts(
22    opts.Curve(width=600, height=400, line_width=2, color='navy')
23)
24
25# Display the result
26hmap