In order to use the
export() functions, users have to install some
additional dependencies. These dependencies can be installed via conda:
conda install selenium phantomjs pillow
Alternatively, you can install phantomjs from npm via
npm install -g phantomjs-prebuilt
Note that the minimum compatible version of PhantomJS is 2.1, regardless of how it is installed.
Bokeh can generate RGBA-format Portable Network Graphics (PNG) images from
layouts using the
export_png() function. This functionality uses a headless
browser called WebKit to render the layout in memory and then capture a
screenshot. The generated image will be of the same dimensions as the source
In order to create a PNG with a transparent background, users should set the
Plot.border_fill_color properties to
Responsive sizing_modes may generate layouts with unexpected size and aspect
ratios. It is recommended to use the default
fixed sizing mode. Also,
glyphs that are rendered via webgl won’t be included in the generated PNG, so
it’s suggested to use the default
The SVG output isn’t as performant as the default Canvas backend when it comes to rendering large number of glyphs or handling lots of user interactions like panning.
Like PNGs, in order to create a SVG with a transparent background, users
should set the
It’s not possible to create a single SVG for a layout of plots, as each plot is it’s own distinct SVG element. Alternatively, it’s possible to download a SVG plot using a SaveTool from the toolbar. However, currently an SVG export of a plot with a toolbar will have a blank area where the toolbar was rendered in the browser.
The SVG backend is activated by setting the
# option one plot = Plot(output_backend="svg") # option two plot.output_backend = "svg"
Exporting a SVG Image¶
Alternatively, it’s possible to download a SVG plot using the
the toolbar isn’t captured though it figures into the plot layout solver
calculations. It’s not great, but a workable option.
For headless export, there’s a utility function,
export_svgs(), which similar
usage to the
show() functions. This function will download all of
SVG-enabled plots within a layout as distinct SVG files.
from bokeh.io import export_svgs plot.output_backend = "svg" export_svgs(plot, filename="plot.svg")