Python 如何使用bokeh select元素使滑块隐藏或不可见?
此示例与bokeh示例不同,滑块可以控制图中的条。(sliders.py) 在我的情况下,左侧有30多个滑块。它看起来有点凌乱,所以我尝试使用bokeh select元素来连接滑块。目标是当我选择时,滑块区域将只显示一个滑块 我阅读了文档,有两种使用方法: 一个是残疾人。如果为True,则小部件将变灰,并且不会响应UI事件。但它不会隐藏。另一个可见,但我得到一个属性错误: AttributeError(“滑块可见的意外属性,禁用类似属性”) 是否可以使bokeh滑块隐藏或不可见?或者有没有其他方法可以让滑块(超过30个)更清晰地区分 下面是可以在Jupyter笔记本中运行的代码Python 如何使用bokeh select元素使滑块隐藏或不可见?,python,bokeh,Python,Bokeh,此示例与bokeh示例不同,滑块可以控制图中的条。(sliders.py) 在我的情况下,左侧有30多个滑块。它看起来有点凌乱,所以我尝试使用bokeh select元素来连接滑块。目标是当我选择时,滑块区域将只显示一个滑块 我阅读了文档,有两种使用方法: 一个是残疾人。如果为True,则小部件将变灰,并且不会响应UI事件。但它不会隐藏。另一个可见,但我得到一个属性错误: AttributeError(“滑块可见的意外属性,禁用类似属性”) 是否可以使bokeh滑块隐藏或不可见?或者有没有其他方
import bokeh.plotting.figure as bk_figure
from bokeh.io import curdoc, show
from bokeh.layouts import row, widgetbox
from bokeh.models import ColumnDataSource, Select
from bokeh.models.widgets import Slider, TextInput
from bokeh.io import output_notebook # enables plot interface in J notebook
import numpy as np
# init bokeh
from bokeh.application import Application
from bokeh.application.handlers import FunctionHandler
output_notebook()
# Set up data
data = {
'line_x' : [1,2,3,4],
'line_y' : [4,3,2,1],
'bar_x':[1, 2, 3, 4],
'bar_bottom':[1,1,1,1],
'bar_top':[0.2, 2.5, 3.7, 4],
}
#bar_color
determine_top = data['bar_top']
determine_bottom = data['bar_bottom']
determine_color = []
for i in range(0,4):
if (determine_top[i] > determine_bottom[i]):
determine_color.append('#B3DE69') #green
else:
determine_color.append('firebrick')
i+=1
data['determine_colors'] = determine_color
source = ColumnDataSource(data=data)
# Set up plot
plot = bk_figure(plot_height=400, plot_width=400, title="test",
tools="crosshair,pan,reset,save,wheel_zoom",
x_range=[0, 10], y_range=[-5, 5])
plot.vbar(x='bar_x', width=0.5, top='bar_top',bottom='bar_bottom',
source=source, color='determine_colors')
# Set up widgets
select = Select(title="days_select:",
options=["d1_select", "d2_select", "d3_select", "d4_select"])
d1 = Slider(title="d1", value=0.0, start=-5.0, end=5.0, step=0.1)
d2 = Slider(title="d2", value=1.0, start=-5.0, end=5.0, step=0.1)
d3 = Slider(title="d3", value=0.0, start=0.0, end=2*np.pi)
d4 = Slider(title="d4", value=1.0, start=0.1, end=5.1, step=0.1)
# Set up callbacks
def update_data(attrname, old, new):
# Get the current slider values
d1_value = d1.value
d2_value = d2.value
d3_value = d3.value
d4_value = d4.value
##select
#if select.value == "d2_select":
# d3.disabled = True
# d4.visible = False
# Generate the new curve
new_data = {
'line_x' : [1,2,3,4],
'line_y' : [4,3,2,1],
'bar_x': [1, 2, 3, 4],
'bar_bottom':[d1_value, d2_value, d3_value, d4_value],
'bar_top':[0.2, d1_value, d2_value, d3_value],
}
#bar_color
determine_top = new_data['bar_top']
determine_bottom = new_data['bar_bottom']
determine_color = []
for i in range(0,4):
if (determine_top[i] > determine_bottom[i]):
determine_color.append('green') #green
else:
determine_color.append('red')
i+=1
new_data['determine_colors'] = determine_color
source.data = new_data
for w in [select, d1, d2, d3, d4]:
w.on_change('value', update_data)
# Set up layouts and add to document
layout = row(widgetbox(select, d1, d2, d3, d4), plot)
def modify_doc(doc):
doc.add_root(row(layout, width=800))
doc.title = "Sliders"
handler = FunctionHandler(modify_doc)
app = Application(handler)
show(app)
谢谢你的建议