我正在使用小部件的bokeh服务器上运行一个交互式应用程序(请参阅下面的测试代码)。在我的简化测试问题中,我有一个数据表(x和y列),我希望在用户使用PointDrawTool修改x-y图时进行更新。但是我希望用户只能修改每个点的y值,而x值对于每个点保持固定。有可能吗?
或者我可以将x轴绘制为x-y数据表的索引(因此是固定的)吗?
'''
Use the ``bokeh serve`` command to run the example by executing:
bokeh serve test.py
at your command prompt. Then navigate to the URL
http://localhost:5006/test
in your browser.
'''
import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import layout, widgetbox, column, row
from bokeh.models import ColumnDataSource, PointDrawTool, Spacer
from bokeh.models.widgets import Slider, Select, Toggle, DataTable, TableColumn, NumberFormatter
from bokeh.plotting import figure
def Steps(attrname, old, new):
n = int(Pts.value)
x=[]
y=[]
for i in range(n+1):
x.append(i)
y.append(i)
source.data = dict(x=x,y=y)
x=[]
y=[]
source = ColumnDataSource(data=dict(x=x, y=y))
# Set up plot
plot0 = figure(plot_width=350, plot_height=350, title = "Load steps", x_axis_label = "x", y_axis_label = "y", tools = "reset", toolbar_location = "right", match_aspect=True, aspect_scale=1.)
plot0.min_border = 40
plot0.toolbar.logo=None
renderer = plot0.scatter('x', 'y', source=source, size=10)
draw_tool = PointDrawTool(renderers=[renderer], empty_value='black', add=False)
plot0.line('x', 'y', source=source, line_width=3, line_alpha=1, color='#b3c100')
plot0.yaxis.axis_label_text_font_size = "12pt"
plot0.yaxis.axis_label_text_font_style = "normal"
plot0.xaxis.axis_label_text_font_size = "12pt"
plot0.title.text_font_size = "16px"
plot0.xaxis.axis_label_text_font_style = "normal"
plot0.x_range.start = 0
plot0.y_range.start = 0
plot0.background_fill_color = "lightgray"
plot0.background_fill_alpha = 0.1
plot0.add_tools(draw_tool)
plot0.toolbar.active_tap = draw_tool
columns = [
TableColumn(field="x", title="x", formatter=NumberFormatter(format='0')),
TableColumn(field="y", title="y", formatter=NumberFormatter(format='00[.]00')),
]
data_table = DataTable(source=source, columns=columns, width=250, height=400, fit_columns=True, editable=True, index_position=None)
Pts = Select(title="No. of steps:", value='1', options=[format(x,'d') for x in range(1,11)])
#----------------------------------------------
for w in [Pts]:
w.on_change('value', Steps)
doc_layout = layout(children=[
[column(widgetbox(Pts, data_table)), plot0]
],
sizing_mode='fixed')
curdoc().add_root(doc_layout)
curdoc().title = "test"