bokeh如何使列数据源列使用第二个Y轴进行显示

时间:2019-10-03 00:47:39

标签: plot bokeh

我正在使用VBar标志符号在Bokeh中显示条形图,并且数据通过ColumnDataSource流到它。此外,在从列中绘制数据时,我想添加其他y轴。

所以代码如下:

self.bar_text = ["V1, "V2", "V3"]
self.plot = figure(x_range=FactorRange(*self.bar_text), y_range=[0, 150])
# Now I add an extra y-axes which is displayed correctly
self.plot.extra_y_ranges = {"delay": Range1d(start=0, end=25)}
self.plot.add_layout(LinearAxis(y_range_name="delay"), 'right')

# The data will be fed to the graph via th column data source
self.input_sources = ColumnDataSource(dict(x=[], top=[], color=[]))
self.bar_glyph = VBar(x="x", top="top", bottom=0, width=0.2, fill_color="color")
self.plot.add_glyph(self.input_sources, self.bar_glyph) 

我可以通过以下方式为它提供数据:

obj.input_sources.stream(dict(x=['V1', 'V2', "V3"],
                                 top=[30, 50, 10],
                                 color=["blue", "blue", "red"]), 3)

但是,我不确定如何将最后一列V3与第二个附加y轴相关联。

1 个答案:

答案 0 :(得分:1)

好,我知道了。答案是为它们使用单​​独的数据源和字形,并将它们分配给正确的y_range

self.left_input_sources = ColumnDataSource(dict(x=[], top=[], color=[]))
self.right_input_sources = ColumnDataSource(dict(x=[], top=[], color=[]))
self.left_bar_glyph = VBar(x="x", top="top", bottom=0, width=0.2, fill_color="color")
self.right_bar_glyph = VBar(x="x", top="top", bottom=0, width=0.2, fill_color="color")
self.plot.add_glyph(self.left_input_sources, self.left_bar_glyph)  # Use default y-axes
self.plot.add_glyph(self.right_input_sources, self.right_bar_glyph, y_range_name='delay')