本文介绍了使用Bokeh,如何保存为png或jpg而不是html文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要导出使用Bokeh创建的图形和绘图的图片.

I need to export pictures of the graphs and plots I am creating with Bokeh.

通常我会

output_file("test.html")

但是,我想将该图形复制到Excel工作表中.它不再必须是交互式的,尽管那会很辉煌.如何将图形导出为图片?使用代码,而不是单击预览/保存".

However, I want to copy that graph into an Excel Sheet.It does not have to be interactive anymore, though that would be brillant.How do I export the graph as a picture? Using code, not clicking on "preview/save".

推荐答案

从散景0.12.6开始,现在可以直接从中导出PNG和SVGPython代码.

As of Bokeh 0.12.6, it is now possible to export PNG and SVG directly fromPython code.

导出PNG看起来像这样

Exporting PNGs looks like this

export_png(plot, filename="plot.png")

导出SVG看起来像这样

And exporting SVGs looks like this

plot.output_backend = "svg"
export_svgs(plot, filename="plot.svg")

需要安装一些可选的依赖项.您可以在《用户指南》的导出图表部分.

There are some optional dependencies that need to be installed.You can find more information in the Exporting Plots section of the User Guide.

这篇关于使用Bokeh,如何保存为png或jpg而不是html文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!