Python 在bokeh服务器中选择线条颜色
我试图允许用户在bokeh服务器中选择线条颜色。我的尝试,适应,如下。但是,线条颜色不会更新。有人知道怎么修吗 此外,是否可以为select传递一些字典,这样选项就不会是十六进制代码/Python 在bokeh服务器中选择线条颜色,python,python-3.x,bokeh,Python,Python 3.x,Bokeh,我试图允许用户在bokeh服务器中选择线条颜色。我的尝试,适应,如下。但是,线条颜色不会更新。有人知道怎么修吗 此外,是否可以为select传递一些字典,这样选项就不会是十六进制代码/ from bokeh.io import show, curdoc from bokeh.models import ColumnDataSource, Legend, CustomJS, Select from bokeh.plotting import figure from bokeh.palettes
from bokeh.io import show, curdoc
from bokeh.models import ColumnDataSource, Legend, CustomJS, Select
from bokeh.plotting import figure
from bokeh.palettes import Category10
from bokeh.layouts import row
import pandas as pd
df0 = pd.DataFrame({'x': [1, 2, 3], 'Ay' : [1, 5, 3], 'A': [0.2, 0.1, 0.2], 'By' : [2, 4, 3], 'B':[0.1, 0.3, 0.2]})
columns = ['A', 'B']
tools_to_show = 'box_zoom,save,hover,reset'
p = figure(plot_height =300, plot_width = 1200,
toolbar_location='above',
tools=tools_to_show)
legend_it = []
color = Category10[10]
columns = ['A', 'B']
source = ColumnDataSource(df0)
c = []
for i, col in enumerate(columns):
c.append(p.line('x', col, source=source, name=col, color=color[i]))
legend_it.append((col, [c[i]]))
legend = Legend(items=legend_it, location=(5,114))#(0, -60))
p.add_layout(legend, 'right')
select = Select(title="color", value=color[0],
options = color)
callbacks = CustomJS(args=dict(renderer=c[0], select=select), code ="""
renderer.glyph.color.value = select.value;
renderer.trigger('change')
""")
select.callback = callbacks
layout = row(select, p)
curdoc().add_root(layout)
JavaScript代码错误,请将其更改为:
renderer.glyph.line_color = select.value;
完美的谢谢