Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting figures from Bokeh as svg or pdf?

Tags:

python

bokeh

Is it possible to output individual figures from Bokeh as pdf or svg images? I feel like I'm missing something obvious, but I've checked the online help pages and gone through the bokeh.objects api and haven't found anything...

like image 934
surfreak Avatar asked Jun 03 '14 23:06

surfreak


People also ask

How do I save a Bokeh figure as a PNG?

Exporting PNG images Bokeh can generate RGBA-format Portable Network Graphics (PNG) images from layouts using the export_png() function. This functionality renders the layout in memory and then captures a screenshot. The output image will have the same dimensions as the source layout.


2 Answers

There is no way to save PDF currently, but as of Bokeh 0.12.6, it is now possible to export PNG and SVG directly from Python code.

Exporting PNGs looks like this

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

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.

like image 124
Optional Argument Avatar answered Oct 20 '22 11:10

Optional Argument


In the meantime... as a workaround, until we get a native support, you can use phantom.js to convert the HTML output into a pdf file. We use it in our example testing directory to convert HTML generated plots into png images, but you could also get pdf images:

  • https://github.com/ContinuumIO/bokeh/blob/master/examples/test#L217

And more info here:

  • http://phantomjs.org/screen-capture.html
like image 39
Damian Avila Avatar answered Oct 20 '22 11:10

Damian Avila