Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With Bokeh, how to save to a png or jpg instead of a html file?

Tags:

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

Usually I do

output_file("test.html") 

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".

like image 466
user2366975 Avatar asked Jun 05 '14 12:06

user2366975


People also ask

How do I save a Bokeh plot 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.

How do I save HTML in Bokeh?

Bokeh creates the HTML file when you call the show() function. This function also automatically opens a web browser to display the HTML file. If you want Bokeh to only generate the file but not open it in a web browser, use the save() function instead.

How do I start a Bokeh server?

You can run and list as many Bokeh servers as you need. To run a Bokeh server instance, use commands similar to the following: serve myapp.py --port 5100 serve myapp.py --port 5101 ... Next, in the location stanza for the Bokeh server, change the proxy_pass value to refer to the upstream stanza above.


1 Answers

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 73
Optional Argument Avatar answered Sep 20 '22 15:09

Optional Argument