python-3.x - 散景图:通过选定的条形图更改线图
问题描述
我一直在寻找,但还没有找到有效的答案,所以我想我会问。
问题
一切都符合规范,除非我单击 statesbp hbar 图,我似乎无法触发获取所选柱值的回调函数(在本例中为 hbar_select)。我在回调函数中添加了一个打印语句,当服务器运行时,我没有在终端中看到这个触发。
我需要做什么才能通过回调选择条形图?
提前致谢,
富有的
hbar_source = ColumnDataSource(data=dict(state=[], sessions=[],))
hbartools = 'tap'
statesbp = figure(y_range=state_data.sort_values('sessions')['state'].values,plot_width=300,plot_height=500, tools='tap', title='Sessions By State')
statesbp.x_range.start = 0
statesbp.hbar(y='state', right='sessions', height=.5, color='navy', source=hbar_source)
def update(selected=None):
data = get_data(state=selected)
source.data = source.from_df(data)
source_static.data = source.data
ts1.title.text = selected
def hbar_select(attrname, old, new):
index_of_selected = new['1d']['indices'][0]
print(index_of_selected)
update(selected = index_of_selected)
def update_hbar():
data = get_states()
hbar_source.data = hbar_source.from_df(data)
#on hbar select, update line chart
hbar_source.on_change('selected',hbar_select)
# initialize data
update()
update_hbar()
curdoc().add_root(series)
curdoc().title = "Website Visits"
解决方案
现在您正在寻找更改,hbar_source.selected
但这不会改变,它将始终是一个 Selection 对象!您应该将此行更改为hbar_source.selected.on_change('indices',hbar_select)
. 当您选择一个条到ColumnDataSource
.
推荐阅读
- complex-event-processing - Esper epl 案例陈述 - 你能说如果 X 在(A、B 或 C)中,那么 Y
- python - 调用函数:select_by_value Selenium Python
- meson-build - 如何使用命令行参数指定外部依赖项包括 dir 和 lib 文件名?
- c# - 尝试将日期时间变量值设置为空
- groovy - 在jenkins groovy管道中迭代列表并利用matches()正则表达式
- reactjs - React PrivateRoute 身份验证和未解决的令牌承诺问题
- css - 固定行和列 HTML 表格,仅使用 CSS 进行水平垂直滚动
- python - 括号中的 Python Pandas 正则表达式数字从列到列表
- sql - oracle sql regexp删除字母t
- javascript - 将 Node/JavaScript 中的格式化日期转换为 UTC