将具有图像的html文件保存在bokeh中 [英] Saving html file with images in bokeh
本文介绍了将具有图像的html文件保存在bokeh中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个包含多个图像的散景图. 我创建并显示如下文件:
I'm creating a bokeh plot containing several images. I create and show my file like this:
output_file(my_dir + "Graphs\\graph")
show(bar)
然后它向我显示该图并在我的目录"Graphs"中创建一个graph.html文件.但是,当我稍后打开html时,该图不包含图像. 如何保存html文件,使其也包含图像?
It then shows me the plot and creates a graph.html file in my directory "Graphs". But when I open the html later, the plot doesn't contain the images. How can I save the html file, so that it contains the images as well?
推荐答案
如文档所述,您有两种方法可以实现此目的:
As the documentation mentions, you have two ways to achieve this:
-
使用
save()
代替show()
from bokeh.plotting import figure, output_file, save
p = figure(title="Basic Title", plot_width=300, plot_height=300)
p.circle([1, 2], [3, 4])
output_file("test.html")
save(p)
使用 file_html
函数,这是低级的
using the file_html
function, which is low-level
from bokeh.plotting import figure
from bokeh.resources import CDN
from bokeh.embed import file_html
plot = figure()
plot.circle([1,2], [3,4])
html = file_html(plot, CDN, "my plot")
with open("/myPath.html") as f:
f.write(html)
这篇关于将具有图像的html文件保存在bokeh中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文