Как я могу ограничить x при использовании PointDrawTool на графике Bokeh? - PullRequest
0 голосов
/ 30 ноября 2018

Я запускаю интерактивное приложение на сервере bokeh (см. Тестовый код ниже), которое использует виджеты.В моей задаче упрощенного теста у меня есть таблица данных (столбцы x и y), которую я хотел бы обновить, когда пользователь изменяет график xy, используя PointDrawTool .Однако я хотел бы, чтобы пользователь мог изменять значение y только для каждой точки, в то время как значение x остается фиксированным для каждой точки.Это как-то возможно?

В качестве альтернативы я могу построить так, чтобы ось x была индексом таблицы данных xy (и, следовательно, фиксированной)?

''' 

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"
...