Python Bokeh嵌入式hplot

时间:2016-05-26 19:53:56

标签: python bokeh

我正在尝试在具有水平布局的网站中嵌入多个散景图表。按照Bokeh用户指南中的示例代码:

from bokeh.io import hplot, output_file, show
from bokeh.plotting import figure

output_file("layout.html")

x = list(range(11))
y0 = x
y1 = [10 - i for i in x]
y2 = [abs(i - 5) for i in x]

# create a new plot
s1 = figure(width=250, plot_height=250, title=None)
s1.circle(x, y0, size=10, color="navy", alpha=0.5)

# create another one
s2 = figure(width=250, height=250, title=None)
s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5)

# create and another
s3 = figure(width=250, height=250, title=None)
s3.square(x, y2, size=10, color="olive", alpha=0.5)

# put all the plots in an HBox
p = hplot(s1, s2, s3)

# show the results
show(p)

它工作正常,但是由于我需要在网页中嵌入图表,我将最后一行替换为:

from bokeh.embed import components
script, div = components(p)
html = "%s\n%s"%(script,div)

这样我就可以将html添加到主页面(与Bokeh CDN一起)。然而,在这种情况下,绘图是垂直组织的,我似乎无法弄清楚是否有解决此问题的方法。 任何建议将不胜感激。

** Edit1:**我似乎已经理解了这个问题,将hplot对象传递给components函数只会创建一个div,它不会以某种方式显示内联图。一种选择是将图表列表传递给组件并添加CSS以使这些div内联。我仍然认为必须有一种我想念的更简单的方法。

0 个答案:

没有答案