每次我从下拉列表中选择不同的类别时,我都试图在bokeh中更新vbar\u堆栈图,但是由于legend_label
在vbar\u图中,我无法在update函数中更新它
我将添加代码以使其更清楚
def make_stacked_bar():
colors = ["#A3E4D7", "#1ABC9C", "#117A65", "#5D6D7E", "#2E86C1", "#1E8449", "#A3E4D7", "#1ABC9C", "#117A65",
"#5D6D7E", "#2E86C1", "#1E8449"]
industries_ = sorted(np.unique(stb_src.data['industries']))
p = figure(x_range=industries_, plot_height=800, plot_width=1200, title="Impact range weight by industry")
targets = list(set(list(stb_src.data.keys())) - set(['industries', 'index']))
p.vbar_stack(targets, x='industries', width=0.9, legend_label=targets, color=colors[:len(targets)], source=stb_src)
以下是更新函数:
def update(attr, old, new):
stb_src.data.update(make_dataset_stack().data)
stb.x_range.factors = sorted(np.unique(stb_src.data['industries']))
如何更新实际数据而不仅仅是x轴? 谢谢
这需要一些非琐碎的工作才能实现。
vbar_stack
方法是一个方便的函数,它实际创建了多个glyph渲染器,在初始堆栈中,每个“行”对应一个。更重要的是,渲染器通过Stack
变换相互关联,该变换在每个步骤中堆叠所有先前的渲染器。因此,实际上并没有任何简单的方法可以更改事后堆叠的行数。以至于我建议在每个回调中删除并重新创建整个绘图(我通常不推荐这种方法,但这种情况是少数例外。)下面是一个基于select小部件更新整个绘图的完整示例:
相关问题 更多 >
编程相关推荐