问题
When I try to change the y axis scale with a bokeh widget, nothing happens. Updating the x range however, does work.
def make_document(doc):
df = some_pandas_dataframe()
x = range(len(df))
plot = figure(sizing_mode='scale_both')
scatters = list()
for l in labels:
scatters.append(plot.step(x=x, y=df[l].sort_values(), alpha=0.2))
x_range_slider = RangeSlider(start=0, end=int(math.ceil(df.shape[0]/1000) * 1000), value=(0, df.shape[0]), step=1, title='Wer hat es geschafft? Der Joshua')
p_layout = layout(plot, x_range_slider)
def update(attr, old, new):
p_layout.children[0].x_range.start = x_range_slider.value[0]
p_layout.children[0].x_range.end = x_range_slider.value[1]
p_layout.children[0].y_scale = LogScale()
p_layout.children[0].y_scale.update()
for wdg in [x_range_slider]:
wdg.on_change('value', update)
doc.title = "Secret"
doc.add_root(p_layout)
apps = {'/': Application(FunctionHandler(make_document))}
server = Server(apps, port=5005, allow_websocket_origin=['*'])
server.start()
In the update function, changing the x range does work. For updating the y scale, I already tried to change the Formatter to LogTickFormatter.
Is it possible to update the scale to log scale and back? Or do I have to reload the entire plot?
回答1:
Is it possible to update the scale to log scale and back?
I would say that dynamically changing a plot's scale is not currently supported. Scales are really only configurable at initialization time. If you need to change scale I would switch to a different version of the plot.
That said, it seems also strange to have the scale change on a Slider
movement (as opposed to some button or toggle, say).
来源:https://stackoverflow.com/questions/48467451/bokeh-server-update-axe-scale