Bokeh autoload

编程入门 行业动态 更新时间:2024-10-10 12:18:33
Bokeh autoload_static仍然是交互式的(Bokeh autoload_static still interactive)

我假设我做错了什么,因为当我尝试使用Bokeh的'autoload_static'功能并将脚本标记放在我的html文件中时,图形仍然是交互式的? 除此之外,尽管它的代码是相同的,但我的脚本标记(通过自动载入静态)的输出与教程看起来不完全一样。

真的很感激帮助。 我试图输出它为静态,所以我可以正确地将其转换为PDF格式的pdfkit - 不幸的是,它不适用于交互式图形。

谢谢!

Html:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Bokeh Scatter Plots</title> <!-- <link rel="stylesheet" href="http://cdn.pydata.org/bokeh/release/bokeh-0.12.7.min.css" type="text/css" /> --> <!-- <script type="text/javascript" src="http://cdn.pydata.org/bokeh/release/bokeh-0.12.7.min.js"></script> --> </head> <body> <script src="js-outputted-by-autoload_static" id="f9632bd4-873b-4c08-a4ad-c8a997873430" data-bokeh-model-id="bec3e18b-71d0-4d3d-9d6a-0079d8fc6082" data-bokeh-doc-id="b39e1b50-1e37-4062-92a8-888cc4424328" ></script> </html>

背景虚化:

from bokeh.resources import CDN from bokeh.plotting import figure from bokeh.embed import autoload_static plot = figure() plot.circle([1,2], [3,4]) js, tag = autoload_static(plot, CDN, "js-outputted-by-autoload_static")

I'm assuming I'm doing something wrong as when I attempt to use Bokeh's 'autoload_static' function and place the script tag in my html file the graph is still interactive? In addition to this, the output of my script tag (by autoload static) doesn't look exactly the same as tutorial despite it being the same code...

Would really appreciate the help. I'm trying to output it as static so I can correctly convert it to pdf with pdfkit - which unfortunately doesn't work with interactive graphs.

Thanks!

Html :

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Bokeh Scatter Plots</title> <!-- <link rel="stylesheet" href="http://cdn.pydata.org/bokeh/release/bokeh-0.12.7.min.css" type="text/css" /> --> <!-- <script type="text/javascript" src="http://cdn.pydata.org/bokeh/release/bokeh-0.12.7.min.js"></script> --> </head> <body> <script src="js-outputted-by-autoload_static" id="f9632bd4-873b-4c08-a4ad-c8a997873430" data-bokeh-model-id="bec3e18b-71d0-4d3d-9d6a-0079d8fc6082" data-bokeh-doc-id="b39e1b50-1e37-4062-92a8-888cc4424328" ></script> </html>

Bokeh:

from bokeh.resources import CDN from bokeh.plotting import figure from bokeh.embed import autoload_static plot = figure() plot.circle([1,2], [3,4]) js, tag = autoload_static(plot, CDN, "js-outputted-by-autoload_static")

最满意答案

autoload_static不用于生成图像 ,它用于生成可以在网页中嵌入标准交互式Bokeh图的JavaScript文件。 “静态”部分是指这些图不由Bokeh服务器支持的事实。

由于autoload_static仍然会生成JavaScript以呈现到HTML画布上,我怀疑它对pdfkit是否有用(我认为它不能对JS代码做任何事情)。

如果您想创建Bokeh图的图像 (例如PNG),则应查看“用户指南”的“ 导出图”部分。 使用Bokeh的最新版本,你可以做例如

from bokeh.io import export_png export_png(plot, filename="plot.png")

生成一个PNG(这大概是pdfkit可以处理的)。 需要安装一些可选的依赖项才能使用此功能,链接的用户指南包含所有信息。

autoload_static is not for generating images, it is for generating JavaScript files that can embed standard interactive Bokeh plots in web pages. The "static" part refers to the fact that these plots are not backed by a Bokeh server.

Since autoload_static still generates JavaScript to render onto an HTML canvas, I doubt it will be useful at all with pdfkit (which I assume cannot do anything with JS code).

If you want to create images (e.g. PNGs) of Bokeh plots, you should look at the Exporting Plots section of the User's Guide. With recent versions of Bokeh, you can do e.g.

from bokeh.io import export_png export_png(plot, filename="plot.png")

to generate a PNG (which presumably is what pdfkit can handle). Some optional dependencies are required to be installed to use this functionality, the linked User's Guide has all the information.

更多推荐

本文发布于:2023-08-03 20:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1400915.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Bokeh   autoload

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!