Существует множество способов, которыми я могу представить это.Предполагая, что вы можете допустить дублирование одного столбца в источнике данных, я бы посоветовал:
import numpy as np
from bokeh.io import show
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, CustomJS, Select
from bokeh.plotting import figure
x = np.linspace(0, 10, 100)
foo = x**2
bar = np.sin(x)
source = ColumnDataSource(data=dict(x=x, y=foo, foo=foo, bar=bar))
plot = figure(plot_height=350)
plot.line(x='x', y='y', source=source)
select = Select(value='foo', options=['foo', 'bar'])
select.js_on_change('value', CustomJS(args=dict(source=source, select=select), code="""
// make a shallow copy of the current data dict
const new_data = Object.assign({}, source.data)
// update the y column in the new data dict from the appropriate other column
new_data.y = source.data[select.value]
// set the new data on source, BokehJS will pick this up automatically
source.data = new_data
"""))
show(column(plot, select))
Если дублирование выбранного столбца в столбце "y" недопустимо, то оно можно обновить глиф, изменить столбец, на который он указывает.Это будет выглядеть примерно так:
r = p.line(x='x', y='foo' source=source)
cb = CustomJS(args=dict(r=r, select=select), code="""
// tell the glyph which field of the source y should refer to
r.glyph.y.field = select.value
// manually trigger change event to re-render
r.glyph.change.emit()
""")