jciemniecki / dknlab_tools

Tools for data processing, analysis, and visualization from the NewmanLab@Caltech.
MIT License
0 stars 0 forks source link

Saving as .svg #1

Open ltsypin opened 4 years ago

ltsypin commented 4 years ago

Thanks for the cool package! I'm trying to save the plots generated by dknlab_tools.viz.plot_growthcurves using dknlab_tools.viz.save as .svgs. I'm getting the following error:

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-67-8342baaa4301> in <module>
----> 1 dknlab_tools.viz.save(oxidation_by_condition_plots, './oxidation_by_condition_plots.svg', filetype='svg')

~/git/dknlab_tools/dknlab_tools/viz.py in save(plot, filename, filetype)
    389     format is html. Can also save as png or svg.
    390     """
--> 391     hv.save(plot, filename, fmt=filetype)

~/miniconda3/lib/python3.7/site-packages/holoviews/util/__init__.py in save(obj, filename, fmt, backend, resources, toolbar, title, **kwargs)
    809             filename = '.'.join(formats[:-1])
    810     return renderer_obj.save(obj, filename, fmt=fmt, resources=resources,
--> 811                              title=title)
    812 
    813 

~/miniconda3/lib/python3.7/site-packages/holoviews/plotting/renderer.py in save(self_or_cls, obj, basename, fmt, key, info, options, resources, title, **kwargs)
    585 
    586         with StoreOptions.options(obj, options, **kwargs):
--> 587             plot, fmt = self_or_cls._validate(obj, fmt)
    588 
    589         if isinstance(plot, Viewable):

~/miniconda3/lib/python3.7/site-packages/holoviews/plotting/renderer.py in _validate(self, obj, fmt, **kwargs)
    295         if fmt not in all_formats:
    296             raise Exception("Format %r not supported by mode %r. Allowed formats: %r"
--> 297                             % (fmt, self.mode, fig_formats + holomap_formats))
    298         self.last_plot = plot
    299         return plot, fmt

Exception: Format 'svg' not supported by mode 'default'. Allowed formats: ['html', 'auto', 'png', 'widgets', 'scrubber', 'gif', 'auto', None]

Does this mean that .svgs are not actually supported, or am I doing something wrong?

ltsypin commented 4 years ago

I ended up writing my own plotter more-or-less equivalent to yours in plain Bokeh, and that seems to work for .svg output. Let me know if you want that code!

jciemniecki commented 4 years ago

After some peeking at the Holoviews source code and troubleshooting, it looks to me like the bokeh backend does not support svg output. I'm fairly certain this was supported in the past but at least right now this isn't the case.

For small sets of plots, when one needs a decent-quality, static image, I suggest the tried-and-true screenshot. For larger sets, html is always a great option.

That's great that you've built something similar in Bokeh! I think that would work perfectly for the next iteration of this package that includes a publication-quality option for output. Let me know if you want to lead that charge on that as a contributor or if you'd rather give me the code to work off of.