散景交互式闪避条形图图例

时间:2020-12-22 08:38:31

标签: bar-chart bokeh legend

我正在探索散景条形图。我想选择我的目标化合物,并绘制它们的平均值和中值。我的代码:

compound = Select(title="Please select compound ", value="O2", options=["O2", "N2"])

# Bar plot mean and median values
source_bp = ColumnDataSource(data=dict(names=[], mean=[], median=[], count=[]))
p2 = figure(x_range=[], plot_height=600,
            title="The Mean & Median O2/N2 Values of the Selected Sample",
            toolbar_location=None, tools="hover", tooltips=[("Value", "@$name"), ("Count", "@count")],
            sizing_mode="stretch_width")

p2.x_range.range_padding = 0.1
p2.xgrid.grid_line_color = None
p2.legend.location = "top_right"
p2.legend.orientation = "horizontal"
p2.xaxis.major_label_orientation = pi / 4


def update_vbar(com):
    p2.vbar(x=dodge("names", +0.1, range=p2.x_range), top='mean', width=0.2, source=source_bp,
            line_color='white', color="#718dbf", legend_label="%s Mean" % com, name="mean")
    p2.vbar(x=dodge("names", -0.1, range=p2.x_range), top='median', width=0.2, source=source_bp,
            line_color='white', color="#e84d60", legend_label="%s Median" % com, name="median")
    p2.yaxis.axis_label = "%s level (mg/kg)" % com
 
def update():
    source_bp.data = bp_dataset(current)
    p2.x_range.factors = source_bp.data.get("names")
    update_vbar(compound.value)

controls = [compound, ..., ]
for control in controls:
    control.on_change('value', lambda attr, old, new: update())

它有效,默认数字为: enter image description here

但是我的化合物选N2后,传说就乱了(虽然数据是对的): enter image description here

如图所示,O2 和 N2 都有图例。能否请你帮忙?先谢谢了。

0 个答案:

没有答案
相关问题