SVG Support for Bokeh Backend
See original GitHub issueI wrote this a while back for HoloExt; was wondering if there’s any interest for me to make a PR for this?
import os
from bokeh import models
from bokeh.io import export_svgs
from holoext.utils import DEFAULT_N, get_cmap, flatten, tidy_fn
def _get_figures_core(objs):
if isinstance(objs, list):
objs = [_get_figures_core(plot) for plot in objs]
elif isinstance(objs, (models.Column, models.Row)):
objs = [_get_figures_core(child) for child in objs.children
if not isinstance(child, (models.ToolbarBox,
models.WidgetBox))]
return objs
def _get_figures(objs):
try:
return list(flatten(_get_figures_core(objs)))
except TypeError:
return [_get_figures_core(objs)]
def _save_to_svg(hv_obj, save):
bokeh_obj = hv.renderer('bokeh').get_plot(hv_obj).state
figures = _get_figures(bokeh_obj)
for i, figure in enumerate(figures):
figure.output_backend = 'svg'
if len(figures) != 1:
if not os.path.exists(save):
os.mkdir(save)
tidied_title = tidy_fn(figure.title.text)
save_fp = os.path.join(
save, '{0}_{1}'.format(tidied_title, i))
else:
save_fp = save
if not save_fp.endswith('svg'):
save_fp = '{0}.{1}'.format(save_fp, 'svg')
export_svgs(figure, save_fp)
import numpy as np
import holoviews as hv
hv.extension('bokeh')
frequencies = [0.5, 0.75, 1.0, 1.25]
def sine_curve(phase, freq):
xvals = [0.1* i for i in range(100)]
return hv.Curve((xvals, [np.sin(phase+freq*x) for x in xvals]))
curve_dict = {f:sine_curve(0,f) for f in frequencies}
NdLayout = hv.NdLayout(curve_dict, kdims='frequency')
_save_to_svg(NdLayout, 'ndlayout_svgs')
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:9 (3 by maintainers)
Top Results From Across the Web
SVG Support for Bokeh Backend #2966 - holoviz/holoviews
I wrote this a while back for HoloExt; was wondering if there's any interest for me to make a PR for this? import...
Read more >Exporting plots — Bokeh 2.4.3 Documentation
Exporting SVG images# · Use the SVG-Crowbar bookmarklet that adds a prompt to download each plot as an SVG file. This tool is...
Read more >Bokeh: how to save a file as svg? - python - Stack Overflow
This is now possible! From the doc: from bokeh.io import export_svgs plot.output_backend = "svg" export_svgs(plot, filename="plot.svg").
Read more >Q3 2021 / Weekly Sync - HackMD
Issue triaging; Working on MathJax bokeh bundle; Python conveniences for LaTeX ... cleaned up PR queue (SVG and latex); followup improvements to SVG...
Read more >Plotting with Matplotlib — HoloViews v1.15.3
'bokeh' backend provides many useful interactive features, the · 'matplotlib' plotting extension is well suited to static exports for printed figures and because ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi guys, I think I’m missing something. I generated from Holoviews some graphs (Scatterplot, Violinplot) and managed to save all of them in svg format, using the following code:
It seems to work properly, so I can’t understand why Bokeh’s guide (https://bokeh.pydata.org/en/latest/docs/user_guide/compat.html) and the code behind Bokeh’s renderer in Holoviews state it is not possible doing this (i.e. exporting to svg format using Bokeh backend, while it is possible from matplotlib). Is there any limitation I can’t see that is preventing this function to be included in Holoviews?
As of Bokeh 0.12.6 it is also possible to export to SVG directly from python. I found this solution pretty straight forward: