1

我正在尝试将 HoloViews + Datashaeder 用作 python 脚本的一部分,而不是仅在笔记本中使用。

我可以创建绘图并在笔记本中查看它,但是当我按照常见问题解答中的示例在没有笔记本的情况下进行渲染时,我收到散景错误:

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'

当我尝试使用 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'

渲染示例代码适用于基本的 holoviews 元素,但是一旦我添加了多个数据着色器方法就会失败。任何帮助,将不胜感激!

4

1 回答 1

1

这可能是一个错误,我已在此处向 HoloViews 提出问题。这里发生的事情是datashade将所谓的流附加到图上,只要轴范围发生变化,它就会更新图。datashade.dynamic=False您可以通过设置datashade 或直接将其传递给调用来手动禁用此行为。

这是您的示例的一个有效版本(另请注意,我已将fig格式更改为,'svg'因为 matplotlib 不会'html'像您最初声明的那样原生呈现:

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')
于 2017-10-10T21:49:47.270 回答