-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathimage.py
More file actions
38 lines (28 loc) · 1.17 KB
/
Copy pathimage.py
File metadata and controls
38 lines (28 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import numpy as np
from bokeh.layouts import column, row
from bokeh.models import ColumnDataSource, CustomJS, Slider
from bokeh.plotting import figure, show
x = np.linspace(0, 10, 500)
y = np.sin(x)
source = ColumnDataSource(data=dict(x=x, y=y))
plot = figure(y_range=(-10, 10), width=400, height=400)
plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)
amp = Slider(start=0.1, end=10, value=1, step=.1, title="Amplitude")
freq = Slider(start=0.1, end=10, value=1, step=.1, title="Frequency")
phase = Slider(start=-6.4, end=6.4, value=0, step=.1, title="Phase")
offset = Slider(start=-9, end=9, value=0, step=.1, title="Offset")
callback = CustomJS(args=dict(source=source, amp=amp, freq=freq, phase=phase, offset=offset),
code="""
const A = amp.value
const k = freq.value
const phi = phase.value
const B = offset.value
const x = source.data.x
const y = Array.from(x, (x) => B + A*Math.sin(k*x+phi))
source.data = { x, y }
""")
amp.js_on_change('value', callback)
freq.js_on_change('value', callback)
phase.js_on_change('value', callback)
offset.js_on_change('value', callback)
show(row(plot, column(amp, freq, phase, offset)))