[英]How to update axis labels from a callback with bokeh?
Any clue on how to update axis labels from a callback ?关于如何从回调更新轴标签的任何线索? Changing the tooltip as well.也改变工具提示。 Also if there is a simpler/better way to code interactions between plots, let me know.此外,如果有更简单/更好的方法来编码图之间的交互,请告诉我。
Here is this minimum example.这是这个最小的例子。
values = list('ABCDFG')
df = pd.DataFrame(np.random.randint(0,100,size=(30, 6)), columns=values)
varName1 = 'A'
varName2 = 'B'
df['x'] = df[varName1]
df['y'] = df[varName2]
source = ColumnDataSource(df)
p0 = figure(tools='pan, wheel_zoom, box_select, lasso_select', plot_width=400, plot_height=400,
active_scroll="wheel_zoom",
x_axis_label=varName1, y_axis_label=varName2,
tooltips=[ (varName1, "@" + varName1),
(varName2, "@" + varName2)
],
title= varName1 + " vs " + varName2)
circles = p0.circle('x', 'y', source=source,
size=15, line_color="navy", fill_color="navy", fill_alpha=0.3)
select1 = Select(title="Variable 1:", value=varName1, width=100, options=values)
select2 = Select(title="Variable 2:", value=varName2, width=100, options=values)
changeVariables = CustomJS(args=dict(plot=p0, source=source, select1=select1, select2=select2, ax1=p0.xaxis, ax2=p0.yaxis), code="""
var varName1 = select1.value;
var varName2 = select2.value;
plot.title.text = varName1 + " vs " + varName2;
ax1[0].axis_label = varName1;
ax2[0].axis_label = varName2;
source.data['x'] = source.data[varName1];
source.data['y'] = source.data[varName2];
source.change.emit();
""")
select1.js_on_change("value", changeVariables)
select2.js_on_change("value", changeVariables)
show(row(p0, select1, select2))
Add this line to your JS callback (works for Bokeh v1.4.0 - v2.1.1):将此行添加到您的 JS 回调(适用于 Bokeh v1.4.0 - v2.1.1):
plot.toolbar.tools[4].tooltips = [[varName1, "@" + varName1], [varName2, "@" + varName2]]
"4" is the index of your HoverTool in the Toolbar “4”是工具栏中 HoverTool 的索引
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.