Skip to content

Commit

Permalink
Merge b3ab9bd into 8314e17
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 24, 2020
2 parents 8314e17 + b3ab9bd commit f1deb47
Showing 1 changed file with 11 additions and 50 deletions.
61 changes: 11 additions & 50 deletions hvplot/utilities.py
@@ -1,65 +1,26 @@
import panel as _pn
import holoviews as _hv

from bokeh.io import export_png as _export_png, show as _show, save as _save
from bokeh.resources import CDN as _CDN

renderer = _hv.renderer('bokeh')

save = _hv.save

def save(obj, filename, title=None, resources=None):
"""
Saves HoloViews objects and bokeh plots to file.
Parameters
----------
obj : HoloViews object
HoloViews object to export
filename : string
Filename to save the plot to
title : string
Optional title for the plot
resources: bokeh resources
One of the valid bokeh.resources (e.g. CDN or INLINE)
"""
if isinstance(obj, _hv.core.Dimensioned):
plot = renderer.get_plot(obj).state
else:
raise ValueError('%s type object not recognized and cannot be saved.' %
type(obj).__name__)

if filename.endswith('png'):
_export_png(plot, filename=filename)
return
if not filename.endswith('.html'):
filename = filename + '.html'

if title is None:
title = 'hvPlot Plot'
if resources is None:
resources = _CDN

if obj.traverse(lambda x: x, [_hv.HoloMap]):
renderer.save(plot, filename)
else:
_save(plot, filename, title=title, resources=resources)


def show(obj, filename=None):
def show(obj, title=None, port=0, **kwargs):
"""
Displays HoloViews objects in and outside the notebook
Parameters
----------
obj : HoloViews object
HoloViews object to export
HoloViews object to export
title : str
A string title to give the Document (if served as an app)
port: int (optional, default=0)
Allows specifying a specific port
**kwargs: dict
Additional keyword arguments passed to Panel show method.
"""
if not isinstance(obj, _hv.core.Dimensioned):
raise ValueError('%s type object not recognized and cannot be shown.' %
type(obj).__name__)

if obj.traverse(lambda x: x, [_hv.HoloMap]):
renderer.app(obj, show=True, new_window=True)
else:
from bokeh.io import output_file
output_file(filename or 'default.html')
_show(renderer.get_plot(obj).state)
_pn.pane.HoloViews(obj).show(title, port, **kwargs)

0 comments on commit f1deb47

Please sign in to comment.