Bokeh,条形图和折线图的组合

标签 bokeh

我正在尝试在 Bokeh 内的条形图顶部绘制一条线。我尝试过:

p1 = figure()...

p1.renderer.append(Bar(...))
p1.renderer.append(Line(...))

show(p1)

到目前为止我还没有运气。

最佳答案

使用 Basic Glyphs 可以在 Bokeh 中的一个图中组合两个或多个图形。 。

对于您的问题,我们可以使用直线和矩形。

from bokeh.plotting import figure, output_file, show
from bokeh.models.ranges import Range1d
import numpy


output_file("line_bar.html")

p = figure(plot_width=400, plot_height=400)

# add a line renderer
p.line([1, 2, 3, 4, 5], [6, 7, 6, 4, 5], line_width=2)

# setting bar values
h = numpy.array([2, 8, 5, 10, 7])

# Correcting the bottom position of the bars to be on the 0 line.
adj_h = h/2

# add bar renderer
p.rect(x=[1, 2, 3, 4, 5], y=adj_h, width=0.4, height=h, color="#CAB2D6")

# Setting the y  axis range   
p.y_range = Range1d(0, 12)

p.title = "Line and Bar"

show(p)

我们得到的情节:

enter image description here

关于Bokeh,条形图和折线图的组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30643681/

相关文章:

python - 如何让 Bokeh HTML 可视化显示在 WordPress 上?

python - IPython Notebook 小部件的 Bokeh : extra figures apppearing

coffeescript - 如何重写 Bokeh 上的方法?如何检查页面上是否已经渲染了所有元素?

python - Bokeh django plot 嵌入 : large amount of white space in generated div tag

javascript - 如何使用 customjs 在 Bokeh 中动态更新下拉菜单选项

python - 如何访问 docker 容器中的内部服务器?

python - 制作脚本内容 'safe' 用于 HTTPS 显示(Bokeh)

python - 条形图的 Bokeh 对数刻度

python - Bokeh :使用复选框小部件隐藏和显示图

javascript - Bokeh:将变量传递给 Widgets 的 CustomJS