Jan Rostenkowski
Jan Rostenkowski

Reputation: 325

Exporting grid of plots as .svg in bokeh

I am using the Bokeh library code here, and trying to export the whole plot (not the text) as a .svg file.

The problem is if I try the following approach:

from bokeh.io import export_png
plot.output_backend = "svg"
export_svgs(plot, filename="plot.svg")

I get NameError: name 'plot' is not defined

If I replace 'plot' with 'grid', it gives me an attribute error.

How can I export the whole gridplot as a .svg?

Upvotes: 3

Views: 1205

Answers (1)

bigreddot
bigreddot

Reputation: 34628

How can I export the whole gridplot as a .svg?

You can't. SVG export works by replacing the standard HTML raster canvas with a "CanvasSVG" that can output SVG when standard HTML canvas drawing calls are made to it. But Bokeh grid plots are not on one giant HTML canvas. They are a grid of separate HTML canvases, which means there is only the possibility of getting a separate SVG for each (if you turn output_backend = "svg" for each subplot individually)

UPDATE: In case it is useful, someone one the Discourse reported on using pdflib to stitch the SVGs together in post processing:

https://discourse.bokeh.org/t/generate-svg-images-from-bokeh-plots-and-include-them-in-a-pdf-report-with-using-svglib-and-reportlab/3889

Upvotes: 2

Related Questions