【发布时间】:2018-07-19 02:06:26
【问题描述】:
我正在使用 ipython 小部件来过滤 pandas 数据框,并相应地更新一些 Bokeh 散点图的数据源。
代码运行正常,没有报错,但是用widget修改过滤参数值还是没有效果。
谁能告诉我问题出在哪里?谢谢!
TOOLS = "box_select,lasso_select,help,hover"
source = ColumnDataSource(data=frame[['A',
'B',
'C'
]])
left = figure(tools=TOOLS,
plot_width=300,
plot_height=300)
left.circle('A', 'C', source=source, size=10)
right = figure(tools=TOOLS,
plot_width=300,
plot_height=300,
title='A',
x_axis_label = "B",
y_axis_label = "C")
right.circle('B', 'C', source=source, size=10)
p = gridplot([[left, right]])
def update(tension):
df = frame[frame['D']==tension]
source = ColumnDataSource(data=df[['A',
'B',
'C'
]])
left.circle('A', 'C', source=source, size=10)
right.circle('B', 'C', source=source, size=10)
p = gridplot([[left, right]])
print(df.shape, tension)
push_notebook()
show(p, notebook_handle=True)
interact(update, tension=frame.D.unique())
使用小部件选择一个值确实会更改“张力”的值并更新“df”数据框,但不会影响绘图。
【问题讨论】:
-
为框架提供样本数据。 @克莱门特
标签: pandas jupyter-notebook bokeh ipywidgets