0
我能夠更新Bokeh服務器渲染器的顏色和線寬,但如果我嘗試更新「尺寸」,則什麼也不會發生。您可以在顏色框中輸入顏色(黑色,綠色,藍色等),並且渲染器會更改顏色。我一直在調整sliders.py示例來測試。代碼如下。如果在update_size方法中將glyph.size更改爲glyph.line_width,則該圖確實會更新線寬,但使用「size」時不會發生任何情況。我使用Python 2.7.12,Ubuntu 16.04,散景服務器0.12.5和Tornado 4.4.2。謝謝您的幫助。無法使用Bokeh服務器交互式更新渲染器(即圓形,三角形等)尺寸
import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import row, widgetbox
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import Slider, TextInput
from bokeh.plotting import figure
# Set up data
N = 200
x = np.linspace(0, 4*np.pi, N)
y = np.sin(x)
source = ColumnDataSource(data=dict(x=x, y=y))
# Set up widgets
text = TextInput(title="title", value='my sine wave')
text2 = TextInput(title="size", value='6')
text3 = TextInput(title="color", value='red')
offset = Slider(title="offset", value=0.0, start=-5.0, end=5.0, step=0.1)
amplitude = Slider(title="amplitude", value=1.0, start=-5.0, end=5.0)
phase = Slider(title="phase", value=0.0, start=0.0, end=2*np.pi)
freq = Slider(title="frequency", value=1.0, start=0.1, end=5.1)
# Set up plot
plot = figure(plot_height=400, plot_width=400, title="my sine wave",
tools="crosshair,pan,reset,save,wheel_zoom",
x_range=[0, 4*np.pi], y_range=[-2.5, 2.5])
r = plot.circle('x', 'y', source=source, size=int(text2.value), line_alpha=0.6, color = text3.value, legend = 'test')
glyph = r.glyph
# Set up callbacks
def update_title(attrname, old, new):
plot.title.text = text.value
text.on_change('value', update_title)
def update_size(attrname, old, new):
glyph.size = int(text2.value)
text2.on_change('value', update_size)
def update_color(attrname, old, new):
glyph.fill_color = text3.value
text3.on_change('value', update_color)
def update_data(attrname, old, new):
# Get the current slider values
a = amplitude.value
b = offset.value
w = phase.value
k = freq.value
# Generate the new curve
x = np.linspace(0, 4*np.pi, N)
y = a*np.sin(k*x + w) + b
source.data = dict(x=x, y=y)
for w in [offset, amplitude, phase, freq]:
w.on_change('value', update_data)
# Set up layouts and add to document
inputs = widgetbox(text, text2, text3, offset, amplitude, phase, freq)
plot.legend.location = "top_left"
plot.legend.click_policy="hide"
curdoc().add_root(row(inputs, plot, width=800))
curdoc().title = "Sliders"
不錯的修復!同時,我將這個bug發佈到github上。 – cuxcrider