Jupyter notebook Bokeh交互式绘图:如何将滑块中的两个(或更多)值相加/相乘。显示电流、电压或声波等示例

Jupyter notebook Bokeh交互式绘图:如何将滑块中的两个(或更多)值相加/相乘。显示电流、电压或声波等示例,jupyter-notebook,bokeh,Jupyter Notebook,Bokeh,我写了以下代码 并希望利用这两个波的数据来创建第三个波。 产生的波浪状电能或声音 from ipywidgets import interact, interactive, fixed, interact_manual # An dieser Stelle und den folgenden "Import" -Aufrufen werden aus Programmbibliotheken fertiger Programmcode und dessen "Funktionen" eing

我写了以下代码

并希望利用这两个波的数据来创建第三个波。 产生的波浪状电能或声音

from ipywidgets import interact, interactive, fixed, interact_manual # An dieser Stelle und den folgenden "Import" -Aufrufen werden aus Programmbibliotheken fertiger Programmcode und dessen "Funktionen" eingebunden.
import numpy as np
from bokeh.io import push_notebook, show, output_notebook
from bokeh.plotting import figure
from bokeh.models import Span
from ipywidgets import interact, interactive, fixed, interact_manual
output_notebook()

x = np.linspace(-5, 5, 3000)
y0 = np.sin(x)

tools = 'pan', 'crosshair', 'wheel_zoom', 'box_zoom', 'reset', 'save'  #https://docs.bokeh.org/en/latest/docs/user_guide/tools.html#userguide-tools-pandrag

TOOLTIPS = [ ("(x,y)", "($x, $y)")] # Hover Tools ermöglicht das Ablesen von x,y- Werten der Datenpunkte


p1 = figure(title="2 Sensor-Signale: Harmonische Schwingung", plot_height=600, plot_width=900, y_range=(-10,10), 
           tooltips=TOOLTIPS, tools=tools, toolbar_location="below")#('pan', 'crosshair'))

p1.xaxis.axis_label = 'Zeit in sec.'
p1.yaxis.axis_label = 'Spannung in Volt'

r1 = p1.line(x, y0, color="#FF0000", line_width=2) 
r2 = p1.line(x, y0, color="#0000CD", line_width=2)

r3 = p1.line(x, r1.data_source.data['y']+ r2.data_source.data['y'])# This is not working

p1.ygrid.minor_grid_line_color = 'navy'
p1.ygrid.minor_grid_line_alpha = 0.1

p1.xgrid.minor_grid_line_color = 'navy'
p1.xgrid.minor_grid_line_alpha = 0.1

vline = Span(location=0, dimension='height', line_color='green', line_width=1)
hline = Span(location=0, dimension='width', line_color='green', line_width=1)
p1.renderers.extend([vline, hline])

def push1(Funkt_ROT="cos", Frequenz1=1, Amplitude1=1, Phasenverschiebung1=0, Offset1=0):
    if   Funkt_ROT == "sin": func1 = np.sin
    elif Funkt_ROT == "cos": func1 = np.cos
    r1.data_source.data['y'] = Amplitude1 * func1(2*np.pi*Frequenz1 * x + (Phasenverschiebung1/360)*2*np.pi) + Offset1

    push_notebook()

def push2(Funkt_BLAU="sin", Frequenz2=1, Amplitude2=1, Phasenverschiebung2=0, Offset2=0):

    if   Funkt_BLAU == "sin": func2 = np.sin
    elif Funkt_BLAU == "cos": func2 = np.cos
    r2.data_source.data['y'] = Amplitude2 * func2(2*np.pi*Frequenz2*x + (Phasenverschiebung2/360)*2*np.pi) + Offset2


    push_notebook()



show(p1, notebook_handle=True)



widget1 = interact(push1, Funkt_ROT=["sin", "cos"], Frequenz1=(1,50), Amplitude1=(0.5, 20, 0.1), Phasenverschiebung1=(0, 360, 0.01), Offset1=(0, 10, 0.05))

widget2 = interact(push2, Funkt_BLAU=["sin", "cos"], Frequenz2=(1,50), Amplitude2=(0.5, 20, 0.1), Phasenverschiebung2=(0, 360, 0.01), Offset2=(0, 10, 0.05))
谢谢你阅读和/或教我这些。
我无法发布,因为详细信息较少…

push\u notebook()
行前面的
push1()
push2()
函数中添加以下行:

r3.data_source.data['y'] = r1.data_source.data['y']+ r2.data_source.data['y']

将以下行添加到函数
push1()
push2()
push\u notebook()
行之前:

r3.data_source.data['y'] = r1.data_source.data['y']+ r2.data_source.data['y']

是 啊非常感谢你!!!“你抓我的背,我就抓你的。”但可能不会很快帮你编程。。。但是,如果你去过德国,你可以骑我的电动自行车去兜风;)谢谢你的提议。很高兴看到您喜欢mybinder.org服务。这使得学习和分享代码变得更加容易。分享结果的好提示:是的!!!非常感谢你!!!“你抓我的背,我就抓你的。”但可能不会很快帮你编程。。。但是,如果你去过德国,你可以骑我的电动自行车去兜风;)谢谢你的提议。很高兴看到您喜欢mybinder.org服务。它使学习和共享代码变得更加容易。分享结果的提示很好: