【发布时间】:2020-07-20 00:27:49
【问题描述】:
我在 Google 协作中使用散景。我想知道是否有人在 Google Collab Jupyter notebook 中使用过 push_notebook。我正在尝试在 Google Collab 上的 Jupiter Notebook 中运行以下代码,但它卡在 push_notebook() 命令上
from ipywidgets import interact
import numpy as np
from bokeh.io import push_notebook,show,output_notebook
from bokeh.plotting import figure
output_notebook()
x=np.linspace(0,2*np.pi,2000)
y=np.sin(x)
p=figure(title="ff",plot_height=300,plot_width=600,y_range=(-5,5))
r=p.line(x,y,color="red",line_width=2)
def update(f,w=1,A=1,phi=0):
print("fff")
if f== "sin":func=np.sin
if f== "sin":func=np.sin
elif f=="cos":func =np.cos
elif f== "tan":func=np.tan
r.data_source.data['y']=A*func(w*x+phi)
push_notebook()
show(p,notebook_handle=True)
interact(update,f=["sin","cos","tan"],w=(0,100),A=(1,5),phi=(0,20,0.1))
任何人都可以建议代码中有什么问题以及如何运行 Google Collab。
【问题讨论】:
标签: jupyter-notebook slider bokeh google-colaboratory ipywidgets