In [26]:
import pandas as pd, numpy as np
idx = pd.date_range('1/1/2000', periods=1000)
df  = pd.DataFrame(np.random.randn(1000, 4), index=idx, columns=list('ABCD')).cumsum()

import hvplot.pandas
In [27]:
import holoviews as hv

hv.extension('bokeh', 'matplotlib')
In [3]:
# hv.extension('matplotlib')
In [4]:
from IPython.display import display_html
In [5]:
hv.Store.renderers
Out[5]:
OrderedDict([('bokeh',
              BokehRenderer(backend='bokeh', css={}, dpi=None, fig='auto', fps=20, holomap='auto', info_fn=<function Exporter.<lambda> at 0x7fadb28e1158>, key_fn=None, mode='default', name='BokehRenderer00089', post_render_hooks={'svg': [], 'png': []}, size=100, theme=None, webgl=False, widget_mode='embed'))])
In [6]:
renderer = hv.Store.renderers['bokeh']
In [11]:
import bokeh.plotting as bkh
bkh.output_notebook()
Loading BokehJS ...
In [14]:
f = bkh.figure(width=600, height=400)
In [38]:
registry = hv.Store.registry['matplotlib']
In [49]:
renderer = hv.plotting.mpl.MPLRenderer.instance(dpi=120)
In [51]:
from IPython.display import display_png
png, info = renderer(df.hvplot(), fmt='png')
display_png(png, raw=True)
In [56]:
%%output backend='matplotlib'
curve
Out[56]:
In [53]:
from IPython.display import display_png
png, info = renderer(curve, fmt='png')
print(info)
display_png(png, raw=True)
{'file-ext': 'png', 'mime_type': 'image/png'}
In [36]:
%%output filename="test" fig="png"
df.hvplot()
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
~/bin/anaconda3/envs/chipnexus/lib/python3.6/site-packages/bokeh/util/dependencies.py in import_required(mod_name, error_msg)
     52     try:
---> 53         return import_module(mod_name)
     54     except ImportError:

~/bin/anaconda3/envs/chipnexus/lib/python3.6/importlib/__init__.py in import_module(name, package)
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 

~/bin/anaconda3/envs/chipnexus/lib/python3.6/importlib/_bootstrap.py in _gcd_import(name, package, level)

~/bin/anaconda3/envs/chipnexus/lib/python3.6/importlib/_bootstrap.py in _find_and_load(name, import_)

~/bin/anaconda3/envs/chipnexus/lib/python3.6/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

~/bin/anaconda3/envs/chipnexus/lib/python3.6/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

~/bin/anaconda3/envs/chipnexus/lib/python3.6/importlib/_bootstrap.py in _gcd_import(name, package, level)

~/bin/anaconda3/envs/chipnexus/lib/python3.6/importlib/_bootstrap.py in _find_and_load(name, import_)

~/bin/anaconda3/envs/chipnexus/lib/python3.6/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'selenium'

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
~/bin/anaconda3/envs/chipnexus/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj, include, exclude)
    968 
    969             if method is not None:
--> 970                 return method(include=include, exclude=exclude)
    971             return None
    972         else:

~/bin/anaconda3/envs/chipnexus/lib/python3.6/site-packages/holoviews/core/dimension.py in _repr_mimebundle_(self, include, exclude)
   1263         combined and returned.
   1264         """
-> 1265         return Store.render(self)
   1266 
   1267 

~/bin/anaconda3/envs/chipnexus/lib/python3.6/site-packages/holoviews/core/options.py in render(cls, obj)
   1287         data, metadata = {}, {}
   1288         for hook in hooks:
-> 1289             ret = hook(obj)
   1290             if ret is None:
   1291                 continue

~/bin/anaconda3/envs/chipnexus/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in pprint_display(obj)
    270     if not ip.display_formatter.formatters['text/plain'].pprint:
    271         return None
--> 272     return display(obj, raw_output=True)
    273 
    274 

~/bin/anaconda3/envs/chipnexus/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in display(obj, raw_output, **kwargs)
    240     elif isinstance(obj, (CompositeOverlay, ViewableElement)):
    241         with option_state(obj):
--> 242             output = element_display(obj)
    243     elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
    244         with option_state(obj):

~/bin/anaconda3/envs/chipnexus/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in wrapped(element)
    140         try:
    141             max_frames = OutputSettings.options['max_frames']
--> 142             mimebundle = fn(element, max_frames=max_frames)
    143             if mimebundle is None:
    144                 return {}, {}

~/bin/anaconda3/envs/chipnexus/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in element_display(element, max_frames)
    186         return None
    187 
--> 188     return render(element)
    189 
    190 

~/bin/anaconda3/envs/chipnexus/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in render(obj, **kwargs)
     63         renderer = renderer.instance(fig='png')
     64 
---> 65     return renderer.components(obj, **kwargs)
     66 
     67 

~/bin/anaconda3/envs/chipnexus/lib/python3.6/site-packages/holoviews/plotting/bokeh/renderer.py in components(self, obj, fmt, comm, **kwargs)
    268         # Bokeh has to handle comms directly in <0.12.15
    269         comm = False if bokeh_version < '0.12.15' else comm
--> 270         return super(BokehRenderer, self).components(obj,fmt, comm, **kwargs)
    271 
    272 

~/bin/anaconda3/envs/chipnexus/lib/python3.6/site-packages/holoviews/plotting/renderer.py in components(self, obj, fmt, comm, **kwargs)
    336             widget_id = plot.id
    337         else:
--> 338             html, js = self._figure_data(plot, fmt, as_script=True, **kwargs)
    339             plot_id = plot.id
    340             if comm and plot.comm is not None and self.comm_msg_handler:

~/bin/anaconda3/envs/chipnexus/lib/python3.6/site-packages/holoviews/plotting/bokeh/renderer.py in _figure_data(self, plot, fmt, doc, as_script, **kwargs)
    297         if fmt == 'png':
    298             from bokeh.io.export import get_screenshot_as_png
--> 299             img = get_screenshot_as_png(plot.state, None)
    300             imgByteArr = BytesIO()
    301             img.save(imgByteArr, format='PNG')

~/bin/anaconda3/envs/chipnexus/lib/python3.6/site-packages/bokeh/io/export.py in get_screenshot_as_png(obj, driver, **kwargs)
    176             file.write(decode_utf8(html))
    177 
--> 178         web_driver = driver if driver is not None else create_webdriver()
    179 
    180         try:

~/bin/anaconda3/envs/chipnexus/lib/python3.6/site-packages/bokeh/io/export.py in create_webdriver()
    289         webdriver = import_required('selenium.webdriver',
    290                                     'To use bokeh.io image export functions you need selenium ' +
--> 291                                     '("conda install -c bokeh selenium" or "pip install selenium")')
    292 
    293         phantomjs_path = detect_phantomjs()

~/bin/anaconda3/envs/chipnexus/lib/python3.6/site-packages/bokeh/util/dependencies.py in import_required(mod_name, error_msg)
     53         return import_module(mod_name)
     54     except ImportError:
---> 55         raise RuntimeError(error_msg)
     56 
     57 def detect_phantomjs(version='2.1'):

RuntimeError: To use bokeh.io image export functions you need selenium ("conda install -c bokeh selenium" or "pip install selenium")
Out[36]:
:NdOverlay   [Variable]
   :Curve   [index]   (value)
In [34]:
%%output backend='bokeh'
df.hvplot()
Out[34]:
In [13]:
display_html(renderer.static_html(df.hvplot()), raw=True)

Bokeh

In [22]:
import numpy as np
import pandas as pd
import bokeh
import bokeh.plotting as bkh
bkh.output_notebook()
Loading BokehJS ...
In [23]:
f = bkh.figure(width=600, height=400)
f.circle(np.random.randn(1000),
         np.random.randn(1000),
         size=np.random.uniform(2, 10, 1000),
         alpha=.5)
bkh.show(f)
In [16]:
import holoviews as hv
hv.extension('bokeh')
In [18]:
data = np.random.rand(100, 100, 10)
In [19]:
ds = hv.Dataset((np.arange(10),
                 np.linspace(0., 1., 100),
                 np.linspace(0., 1., 100),
                 data),
                kdims=['time', 'y', 'x'],
                vdims=['z'])
In [20]:
ds
Out[20]:
:Dataset   [time,y,x]   (z)
In [21]:
%opts Image(cmap='viridis')
ds.to(hv.Image, ['x', 'y']).hist()
Out[21]: