Exporting Plots
Bokeh exports plots to static artifacts: standalone HTML files, PNG/SVG images (via headless rendering), and embedded snippets. The output_file/output_notebook/output_file functions set the destination, and export_png/export_svg (through Bokeh's export utilities) produce raster or vector images for documents and slides.
Exporting to Standalone HTML
from bokeh.plotting import figure, output_file, show
output_file("plot.html")
p = figure(title="Export demo")
p.circle([1, 2, 3], [1, 2, 3])
show(p) # writes plot.html
The HTML is self-contained (inlines the Bokeh JS) and can be opened in any browser or uploaded to a static host.
Exporting to PNG
from bokeh.io import export_png
export_png(p, "plot.png", size=(800, 400))
export_png uses a headless browser (Playwright in recent Bokeh) to render the plot to an image. SVG works the same way with export_svg for vector output suitable for manuscripts.
Exporting to SVG
from bokeh.io import export_svg
export_svg(p, "plot.svg", size=(800, 400))
Controlling Size and Quality
# set the plot size before export for predictable output
p.width = 800
p.height = 400
export_png(p, "plot.png")
# for sharper raster output, export at 2x and downscale downstream
A Practical Export Workflow
- Build the plot (or layout) in code with fixed width/height for reproducible output.
- Call export_png/export_svg with an explicit size for documents.
- For web, export a self-contained HTML and host it statically.
- Keep the generating script under version control so exports are regenerable.
Summary
Export Bokeh plots with output_file + show for standalone HTML, and export_png/export_svg (headless rendering) for raster or vector images with an explicit size. Use fixed plot dimensions for reproducible exports, and keep the plot code in a script so figures can be regenerated on demand.