每次我从下拉列表中选择不同的类别时,我都会尝试在散景中更新 vbar_stack 图,但是legend_label
在 vbar_plot 内部,我无法在更新函数中更新它。
我将添加代码以更清晰
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 轴?谢谢!