我对bokeh(使用jupyter)相当新,我试图使用下拉按钮创建一个简单的线和散点图,我可以为x轴和y轴选择一组值并查看它们实时更新但由于某种原因图表无法正确更新,这是我的代码的一部分:
weight= [23,45,11,40]
velocity= [12,65,32,15]
momentum = [12,78,22,40]
p = figure(plot_height=300,plot_width=500,title="Graph line of DATA")
p.title.text_font_style = "bold"
r = p.line(weight,velocity, color="red", line_width=3)
tab1=Panel(child=p, title="line")
p1 = figure(plot_height=300,plot_width=500,title="Graph line of DATA")
r1 = p1.circle(weight,velocity, size=10, color="red", alpha=0.5)
p1.title.text_font_style = "bold"
tab2=Panel(child=p1, title="Circle")
def updatex(Xaxis):
if Xaxis == "Weight":
func = weight
p.xaxis.axis_label = "pounds"
p1.xaxis.axis_label = "pounds"
elif Xaxis == "Velocity":
func = velocity
p.xaxis.axis_label = "m/s"
p1.xaxis.axis_label = "m/s"
elif Xaxis == "Momemtum":
func = momentum
p.xaxis.axis_label = "lb-sec"
p1.xaxis.axis_label = "lb-sec"
r.data_source.data['x'] = func
r1.data_source.data['x'] = func
push_notebook()
def updatey(Yaxis):
if Yaxis == "Weight":
func = weight
p.xaxis.axis_label = "pounds"
p1.xaxis.axis_label = "pounds"
elif Yaxis == "Velocity":
func = velocity
p.xaxis.axis_label = "m/s"
p1.xaxis.axis_label = "m/s"
elif Xaxis == "Momemtum":
func = momentum
p.xaxis.axis_label = "lb-sec"
p1.xaxis.axis_label = "lb-sec"
r.data_source.data['y'] = func
r1.data_source.data['y'] = func
push_notebook()
# the following snippet would be in the following cell below:
interact(updatex,Xaxis=["Weight", "Velocity", "Momemtum"])
interact(updatey,Yaxis=["Weight","Velocity","Momemtum"])