【发布时间】:2020-02-09 20:14:12
【问题描述】:
LS, 关于同一主题的所有答案都没有帮助我解决我的更新问题。我认为这与 dfs = df.sort_values(by=['E']) 有关。我使用所有最新版本的库。散景网站上的示例在我的配置上运行良好。通过更新按钮,我想允许用户选择首选的排序顺序。当这部分工作时,将添加另外两个排序按钮。 这是我的代码:
import pandas as pd
from bokeh.plotting import figure, curdoc
from bokeh.models import ColumnDataSource
from bokeh.layouts import gridplot
from bokeh.models import Button
df = pd.DataFrame(dict(A=["AMS", "LHR", "FRA", "PTY", "CGD"], S=[7,-5,-3,3,2], E=[8,3,-2,5,8], C=[5,2,7,-3,-4]))
source = ColumnDataSource(df)
options = dict(plot_width=300, plot_height=200,
tools="pan,wheel_zoom,box_zoom,box_select,lasso_select")
button = Button(label="Change Sort to E")
p1 = figure(y_range=source.data['A'].tolist(), title="S", **options)
p1.hbar(y='A', right="S", height=0.2, source=source)
p2 = figure(y_range=source.data['A'].tolist(), title="E", **options)
p2.hbar(y="A", right="E", height=0.2, source=source)
p3 = figure(y_range=source.data['A'].tolist(), title="C", **options)
p3.hbar(y="A", right="C", height=0.2, source=source)
def update():
dfs = df.sort_values(by=['E'])
source.data = ColumnDataSource.from_df(dfs)
button.on_click(update)
p = gridplot([[button], [p1, p2, p3]], toolbar_location="right")
curdoc().add_root(p)
我通过以下方式运行服务器:bokeh serve --show app.py --port 5009
非常感谢您进行更新。
【问题讨论】: