1 回答

TA貢獻1831條經驗 獲得超9個贊
你已經給自己答案了。使用components是實現它的一種方式。請查看Bokeh 嵌入文檔以了解所有選項。
如果您想要一個可以使用此方法的單個文件實現(使用 Bokeh 1.1.0 測試):
from jinja2 import Template
from bokeh.plotting import figure
from bokeh.embed import file_html
from bokeh.models import Div, Paragraph, Row, Column
from bokeh.resources import CDN
from bokeh.util.browser import view
template = Template("""
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{{ title if title else "Bokeh Plot" }}</title>
{{ bokeh_css | safe }}
{{ bokeh_js | safe }}
</head>
<body>
{{ plot_div | safe }}
{{ plot_script | safe }}
</body>
</html> """)
p1 = figure(plot_width = 400, plot_height = 400)
p2 = figure(plot_width = 400, plot_height = 400)
p3 = figure(plot_width = 800, plot_height = 400)
p1.circle([1, 2, 3], [4, 5, 6])
p2.line([1, 2, 3], [4, 5, 6])
p3.line([1, 2, 3], [4, 5, 6])
html = file_html(Column(Row(p1, p2), Row(p3)), template = template, resources = CDN)
output_file = 'css_classes.html'
with open(output_file, 'w') as f:
f.write(html)
view(output_file)
結果:
添加回答
舉報