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".
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.
OK, correcting to myself, I miss your part about not using the preview/save... Currently we do not provide a direct programmatic way to export Bokeh plots to a png file. You will need the user interaction even using internal functions. We could probably add a feature like that in the feature.
Cheers.
I asked a similar question yesterday. The linked solution may work for you. Basically you open the file in a web page, take a screen shot which you can then crop and save as an image.
Python open html file, take screenshot, crop and save as image
来源:https://stackoverflow.com/questions/24060173/with-bokeh-how-to-save-to-a-png-or-jpg-instead-of-a-html-file