1

I’m trying to use HoloViews + Datashaeder as part of a python script instead of exclusively in notebooks.

I can create the plot and view it in a notebook but when I follow the example from the FAQ for rendering without the notebook, I receive errors for bokeh:

import holoviews as hv
import numpy as np
from holoviews.operation.datashader import datashade, dynspread
hv.extension('bokeh')

np.random.seed(1)
positions = np.random.multivariate_normal((0,0),[[0.1,0.1], [0.1,1.0]], (1000000,))
points = hv.Points(positions,label="Points")
plot = datashade(points) + dynspread(datashade(points))

renderer = hv.renderer('matplotlib').instance(fig='html')
renderer.save(plot,'testing')

Traceback (most recent call last):
  File "holoviews_test.py", line 21, in <module>
    renderer.save(plt_out, 'exampleFAQ2') 
  File "/anaconda2/lib/python2.7/site-
    packages/holoviews/plotting/renderer.py", line 465, in save
    plot = self_or_cls.get_plot(obj)
  File "/anaconda2/lib/python2.7/site-
    packages/holoviews/plotting/bokeh/renderer.py", line 112, in get_plot
    plot = super(BokehRenderer, self_or_cls).get_plot(obj, renderer)
  File "/anaconda2/lib/python2.7/site-
    packages/holoviews/plotting/renderer.py", line 177, in get_plot
    **plot_opts)
  File "/anaconda2/lib/python2.7/site-
    packages/holoviews/plotting/bokeh/raster.py", line 20, in __init__
    super(RasterPlot, self).__init__(*args, **kwargs)
  File "/anaconda2/lib/python2.7/site-
    packages/holoviews/plotting/bokeh/element.py", line 180, in __init__
    self.callbacks = self._construct_callbacks()
  File "/anaconda2/lib/python2.7/site-
    packages/holoviews/plotting/bokeh/element.py", line 216, in _construct_callbacks
    cbs.append(cb(self, cb_streams, source))
  File "/anaconda2/lib/python2.7/site-
    packages/holoviews/plotting/bokeh/callbacks.py", line 54, in __init__
    self.comm = self._comm_type(plot, on_msg=self.on_msg)
  File "/anaconda2/lib/python2.7/site-
    packages/holoviews/plotting/comms.py", line 210, in __init__
    self.manager = get_ipython().kernel.comm_manager
 AttributeError: 'NoneType' object has no attribute 'kernel'

and when I try to make the same plot with matplotlib:

hv.extension('matplotlib')
renderer = hv.renderer('matplotlib').instance(fig='png')
renderer.save(plot,'testing')

Traceback (most recent call last):
  File "holoviews_test.py", line 21, in <module>
    renderer.save(plt_out, 'exampleFAQ2') #, style=dict(Image=
    {'cmap':'jet'}))
  File "/anaconda2/lib/python2.7/site-
    packages/holoviews/plotting/renderer.py", line 465, in save
    plot = self_or_cls.get_plot(obj)
  File "/anaconda2/lib/python2.7/site-
    packages/holoviews/plotting/renderer.py", line 178, in get_plot
    plot.update(0)
  File "/anaconda2/lib/python2.7/site-
    packages/holoviews/plotting/mpl/plot.py", line 244, in update
    return self.initialize_plot()
  File "/anaconda2/lib/python2.7/site-
    packages/holoviews/plotting/mpl/plot.py", line 43, in wrapper
    return f(self, *args, **kwargs)
  File "/anaconda2/lib/python2.7/site-
    packages/holoviews/plotting/mpl/plot.py", line 1090, in 
    initialize_plot
    hspace=self.hspace*self.fig_scale)
  File "/anaconda2/lib/python2.7/site-
    packages/holoviews/plotting/mpl/util.py", line 113, in fix_aspect
    bbox = ax.get_tightbbox(fig.canvas.renderer)
AttributeError: 'FigureCanvasMac' object has no attribute 'renderer'

The rendering example code works for basic holoviews Elements but fails once I add the multiple datashader methods. Any help would be appreciated!

laurennc
  • 13
  • 7

1 Answers1

3

This is likely a bug and I've filed an issue with HoloViews here. What is happening here is that datashade attaches so called streams to the plot which update the plot whenever the axis ranges change. You can manually disable this behavior by setting datashade.dynamic=False on datashade or pass it directly to the call.

Here's a version of your example that works (note also that I've changed the fig format to 'svg' since matplotlib does not render natively to 'html' as you had originally declared:

import holoviews as hv
import numpy as np
from holoviews.operation.datashader import datashade, dynspread
hv.extension('bokeh')

#### Disable dynamic updating of plot
datashade.dynamic = False

np.random.seed(1)
positions = np.random.multivariate_normal((0,0),[[0.1,0.1], [0.1,1.0]], (1000000,))
points = hv.Points(positions,label="Points")
plot = datashade(points, dynamic=False) + dynspread(datashade(points))

renderer = hv.renderer('matplotlib').instance(fig='svg')
renderer.save(plot,'testing')
philippjfr
  • 3,997
  • 14
  • 15
  • If I add the dynamic keyword as well as specifying x_range and y_range for the datashade function, the plot will save using bokeh + html. However, this code with matplotlib gives me the same FigureCanvasMac error as above. Maybe it's my matplotlib version? I'm currently using matplotlib 2.0.0, holoviews 1.8.3, and datashader 0.4.0 – laurennc Oct 11 '17 at 15:40