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

- 878
- 1
- 8
- 17
-
Support is planned. See https://github.com/bokeh/bokeh/issues/538#issuecomment-157931426 and https://groups.google.com/a/continuum.io/d/msg/bokeh/9lRQsnr-Dok/hMZQ28ZAS-QJ – koppor Jan 08 '16 at 22:55
-
It is possible to create a pdf from bokeh using a svg export and tranforming the svg into pdf. All done using python. To see a complete example check this [SO-Post](https://stackoverflow.com/questions/66045107/how-to-save-a-bokeh-plot-as-pdf/66045108#66045108). – mosc9575 Aug 17 '22 at 06:24
4 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.

- 526
- 6
- 6
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:
And more info here:

- 775
- 8
- 8
-
Okay, investigating now... I'll update this if I get a working solution. – groundlar Jun 05 '14 at 09:50
-
1This works, but it only uses a screenshot of the page: I'm looking for something that allows me to save this in a scalable format. I guess I should've specified that in the question. – groundlar Jun 05 '14 at 11:18
-
Yep, not a complete solution yet, but we are discussing some possibilities to address this issue in the future. – Damian Avila Jun 07 '14 at 13:28
-
1
-
This is no longer necessary please see the new answer about `export_png` and `export_svgs` – bigreddot Jun 14 '17 at 16:51
So, it's 2022 now and there's no direct support for exporting images as pdf. However, there is a alternative way which works just as well.
First, as the other answers have mentioned, set the backend to 'svg'.
plot.output_backend = "svg"
then save the image as an svg file. Do not save it as an html file as this will likely lead to extra space around the actual image.
Then use any online svg to pdf convertor to get the pdf equivalent of the svg.

- 71
- 5
-
1There is no need to use a online converter. A SVG to PDF converte exists in python, too. To see a complete example, check this [question](https://stackoverflow.com/questions/66045107/how-to-save-a-bokeh-plot-as-pdf/). – mosc9575 Aug 17 '22 at 06:30