简体   繁体   English

Jupyter Notebook中的交互式散景图未更新

[英]Interactive Bokeh plot in Jupyter Notebook not updating

I have written the following little script with which I simply want to plot an interactive sine curve where I can change the amplitude of the curve and the title of the figure. 我编写了以下小脚本,我只想用它绘制交互式正弦曲线,即可在其中更改曲线的幅值和图形标题。 Though, as output I get the figure together with the slider and text field but altering the values does not change the curve or title. 但是,作为输出,我将图形与滑块和文本字段一起获得,但是更改值不会更改曲线或标题。

import numpy as np
from bokeh.io import push_notebook
import pandas as pd
from ipywidgets import interact
from bokeh.layouts import widgetbox
from bokeh.io import push_notebook

x = np.linspace(0,2*np.pi,2000)
y = np.sin(x)

df_data = pd.DataFrame({'x':x,'y':y})

p = figure(plot_height=300,plot_width=600,title="my sine wave")
p.line('x','y',source=df_data)


# Set up widges
amplitude = Slider(title="amlitude", value=0.0, start=0.01, end=0.99, step=0.01)
text = TextInput(title="title", value='my sine wave')

# Update
def update_data(attrname, old, new):

    # Get the current slider values
    a = amplitude.value
    b = text.value

    y = amplitude*np.sin(x)


    output_notebook()
    show(row(p,widgetbox([amplitude,text])))




text.on_change('value', update_data)
amplitude.on_change('value',update_data)



# Set to output the plot in the notebook

output_notebook()
show(row(p,widgetbox([amplitude,text])))

在此处输入图片说明

So as you can see, everything works fine instead of the updating of the plot. 如您所见,一切正常,而不是更新情节。

everything works fine instead of the updating of the plot. 一切正常,而不是更新情节。

Within update_data you have to show() again as in your bottom lines or it won't refresh. update_data您必须再次show() ,如其底行所示,否则它不会刷新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM