Holoviews“点”与数据着色器一起工作,但“曲线”抛出错误

问题描述

我正在 Jupyter Notebook 中使用 Python 处理大数据(约 2500 万个点),并希望拥有一个不会永远加载的交互式图表。使用 bokeh 为我提供了交互性,Holoviews 和 Datashader 允许相对快速地绘制数据。

Python:3.7.6
散景:1.4.0
全息视图:1.14.3
Numpy:1.19.5
熊猫:1.0.1
数字:0.48.0

我运行这个示例代码没有问题:

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

n = 100000
dates = pd.date_range(start='1990-01-01',freq='1T',periods=n)
point = hv.Points((dates,np.random.normal(size=(n,))))
datashade(point,cmap=['red']).opts(width=800)

给出了一个很好的图表:

enter image description here

但是当我将 Holoviews 选项从“点”切换到“曲线”(这是原始代码)时:

import numpy as np,periods=n)
curve = hv.Curve((dates,))))
datashade(curve,cmap=['red']).opts(width=800)

我收到了这么长的错误

WARNING:param.dynamic_operation: Callable raised "TypingError('Failed in nopython mode pipeline (step: nopython frontend)\n\x1b[1m\x1b[1m\x1b[1m\x1b[1mFailed in nopython mode pipeline (step: nopython frontend)\n\x1b[1m\x1b[1m\x1b[1m\x1b[1mFailed in nopython mode pipeline (step: nopython frontend)\n\x1b[1m\x1b[1m\x1b[1m\x1b[1mFailed in nopython mode pipeline (step: nopython frontend)\nInternal error at <numba.typeinfer.StaticGetItemConstraint object at 0x0000021D40ACEC88>.\n\x1b[1m\x1b[1mtuple index out of range\x1b[0m\n\x1b[0m\x1b[1m[1] During: typing of static-get-item at C:\\Users\\HornLab\\Anaconda3\\lib\\site-packages\\datashader\\glyphs\\line.py (653)\x1b[0m\nEnable logging at debug level for details.\n\x1b[1m\nFile "..\\..\\..\\Anaconda3\\lib\\site-packages\\datashader\\glyphs\\line.py",line 653:\x1b[0m\n\x1b[1mdef _xiaolinwu(i,x0,x1,y0,y1,append,*aggs_and_cols):\n    <source elided>\n    agg = aggs_and_cols[0]\n\x1b[1m    cols = aggs_and_cols[1]\n\x1b[0m    \x1b[1m^\x1b[0m\x1b[0m\n\n\x1b[0m\x1b[1m[1] During: resolving callee type: type(cpudispatcher(<function _xiaolinwu at 0x0000021D2E0B98B8>))\x1b[0m\n\x1b[0m\x1b[1m[2] During: typing of call at <draw_segment> (33)\n\x1b[0m\n\x1b[0m\x1b[1m[3] During: resolving callee type: type(cpudispatcher(<function _xiaolinwu at 0x0000021D2E0B98B8>))\x1b[0m\n\x1b[0m\x1b[1m[4] During: typing of call at <draw_segment> (33)\n\x1b[0m\n\x1b[1m\nFile "<draw_segment>",line 33:\x1b[0m\n\x1b[1m<source missing,REPL/exec in use?>\x1b[0m\n\n\x1b[0m\x1b[1m[1] During: resolving callee type: type(cpudispatcher(<function draw_segment at 0x0000021D4063DAF8>))\x1b[0m\n\x1b[0m\x1b[1m[2] During: typing of call at <perform_extend_line> (13)\n\x1b[0m\n\x1b[0m\x1b[1m[3] During: resolving callee type: type(cpudispatcher(<function draw_segment at 0x0000021D4063DAF8>))\x1b[0m\n\x1b[0m\x1b[1m[4] During: typing of call at <perform_extend_line> (13)\n\x1b[0m\n\x1b[1m\nFile "<perform_extend_line>",line 13:\x1b[0m\n\x1b[1m<source missing,REPL/exec in use?>\x1b[0m\n\n\x1b[0m\x1b[1m[1] During: resolving callee type: type(cpudispatcher(<function perform_extend_line at 0x0000021D4063DE58>))\x1b[0m\n\x1b[0m\x1b[1m[2] During: typing of call at <extend_cpu> (10)\n\x1b[0m\n\x1b[0m\x1b[1m[3] During: resolving callee type: type(cpudispatcher(<function perform_extend_line at 0x0000021D4063DE58>))\x1b[0m\n\x1b[0m\x1b[1m[4] During: typing of call at <extend_cpu> (10)\n\x1b[0m\n\x1b[1m\nFile "<extend_cpu>",line 10:\x1b[0m\n\x1b[1m<source missing,REPL/exec in use?>\x1b[0m\n')".
Invoked as dynamic_operation(height=400,scale=1.0,width=400,x_range=None,y_range=None)
WARNING:param.dynamic_operation: Callable raised "TypingError('Failed in nopython mode pipeline (step: nopython frontend)\n\x1b[1m\x1b[1m\x1b[1m\x1b[1mFailed in nopython mode pipeline (step: nopython frontend)\n\x1b[1m\x1b[1m\x1b[1m\x1b[1mFailed in nopython mode pipeline (step: nopython frontend)\n\x1b[1m\x1b[1m\x1b[1m\x1b[1mFailed in nopython mode pipeline (step: nopython frontend)\nInternal error at <numba.typeinfer.StaticGetItemConstraint object at 0x0000021D40ACEC88>.\n\x1b[1m\x1b[1mtuple index out of range\x1b[0m\n\x1b[0m\x1b[1m[1] During: typing of static-get-item at C:\\Users\\HornLab\\Anaconda3\\lib\\site-packages\\datashader\\glyphs\\line.py (653)\x1b[0m\nEnable logging at debug level for details.\n\x1b[1m\nFile "..\\..\\..\\Anaconda3\\lib\\site-packages\\datashader\\glyphs\\line.py",y_range=None)
---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
~\Anaconda3\lib\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:

~\Anaconda3\lib\site-packages\holoviews\core\dimension.py in _repr_mimebundle_(self,exclude)
   1315         combined and returned.
   1316         """
-> 1317         return Store.render(self)
   1318 
   1319 

~\Anaconda3\lib\site-packages\holoviews\core\options.py in render(cls,obj)
   1403         data,Metadata = {},{}
   1404         for hook in hooks:
-> 1405             ret = hook(obj)
   1406             if ret is None:
   1407                 continue

~\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in pprint_display(obj)
    280     if not ip.display_formatter.formatters['text/plain'].pprint:
    281         return None
--> 282     return display(obj,raw_output=True)
    283 
    284 

~\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in display(obj,raw_output,**kwargs)
    256     elif isinstance(obj,(HoloMap,DynamicMap)):
    257         with option_state(obj):
--> 258             output = map_display(obj)
    259     elif isinstance(obj,Plot):
    260         output = render(obj)

~\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in wrapped(element)
    144         try:
    145             max_frames = OutputSettings.options['max_frames']
--> 146             mimebundle = fn(element,max_frames=max_frames)
    147             if mimebundle is None:
    148                 return {},{}

~\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in map_display(vmap,max_frames)
    204         return None
    205 
--> 206     return render(vmap)
    207 
    208 

~\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in render(obj,**kwargs)
     66         renderer = renderer.instance(fig='png')
     67 
---> 68     return renderer.components(obj,**kwargs)
     69 
     70 

~\Anaconda3\lib\site-packages\holoviews\plotting\renderer.py in components(self,fmt,comm,**kwargs)
    408                 doc = Document()
    409                 with config.set(embed=embed):
--> 410                     model = plot.layout._render_model(doc,comm)
    411                 if embed:
    412                     return render_model(model,comm)

~\Anaconda3\lib\site-packages\panel\viewable.py in _render_model(self,doc,comm)
    425         if comm is None:
    426             comm = state._comm_manager.get_server_comm()
--> 427         model = self.get_root(doc,comm)
    428 
    429         if config.embed:

~\Anaconda3\lib\site-packages\panel\viewable.py in get_root(self,preprocess)
    482        
    483         doc = init_doc(doc)
--> 484         root = self._get_model(doc,comm=comm)
    485         if preprocess:
    486             self._preprocess(root)

~\Anaconda3\lib\site-packages\panel\layout\base.py in _get_model(self,root,parent,comm)
    111         if root is None:
    112             root = model
--> 113         objects = self._get_objects(model,[],comm)
    114         props = dict(self._init_params(),objects=objects)
    115         model.update(**self._process_param_change(props))

~\Anaconda3\lib\site-packages\panel\layout\base.py in _get_objects(self,model,old_objects,comm)
    101             else:
    102                 try:
--> 103                     child = pane._get_model(doc,comm)
    104                 except RerenderError:
    105                     return self._get_objects(model,current_objects[:i],comm)

~\Anaconda3\lib\site-packages\panel\pane\holoviews.py in _get_model(self,comm)
    237             plot = self.object
    238         else:
--> 239             plot = self._render(doc,root)
    240 
    241         plot.pane = self

~\Anaconda3\lib\site-packages\panel\pane\holoviews.py in _render(self,root)
    302                 kwargs['comm'] = comm
    303 
--> 304         return renderer.get_plot(self.object,**kwargs)
    305 
    306     def _cleanup(self,root):

~\Anaconda3\lib\site-packages\holoviews\plotting\bokeh\renderer.py in get_plot(self_or_cls,renderer,**kwargs)
     71         combining the bokeh model with another plot.
     72         """
---> 73         plot = super(bokehRenderer,self_or_cls).get_plot(obj,**kwargs)
     74         if plot.document is None:
     75             plot.document = Document() if self_or_cls.notebook_context else curdoc()

~\Anaconda3\lib\site-packages\holoviews\plotting\renderer.py in get_plot(self_or_cls,**kwargs)
    218 
    219         # Initialize DynamicMaps with first data item
--> 220         initialize_dynamic(obj)
    221 
    222         if not renderer:

~\Anaconda3\lib\site-packages\holoviews\plotting\util.py in initialize_dynamic(obj)
    250             continue
    251         if not len(dmap):
--> 252             dmap[dmap._initial_key()]
    253 
    254 

~\Anaconda3\lib\site-packages\holoviews\core\spaces.py in __getitem__(self,key)
   1339         # Not a cross product and nothing cached so compute element.
   1340         if cache is not None: return cache
-> 1341         val = self._execute_callback(*tuple_key)
   1342         if data_slice:
   1343             val = self._dataslice(val,data_slice)

~\Anaconda3\lib\site-packages\holoviews\core\spaces.py in _execute_callback(self,*args)
   1108 
   1109         with dynamicmap_memoization(self.callback,self.streams):
-> 1110             retval = self.callback(*args,**kwargs)
   1111         return self._style(retval)
   1112 

~\Anaconda3\lib\site-packages\holoviews\core\spaces.py in __call__(self,*args,**kwargs)
    712 
    713         try:
--> 714             ret = self.callable(*args,**kwargs)
    715         except KeyError:
    716             # KeyError is caught separately because it is used to signal

~\Anaconda3\lib\site-packages\holoviews\util\__init__.py in dynamic_operation(*key,**kwargs)
   1040 
   1041         def dynamic_operation(*key,**kwargs):
-> 1042             key,obj = resolve(key,kwargs)
   1043             return apply(obj,*key,**kwargs)
   1044 

~\Anaconda3\lib\site-packages\holoviews\util\__init__.py in resolve(key,kwargs)
   1029             elif isinstance(map_obj,DynamicMap) and map_obj._posarg_keys and not key:
   1030                 key = tuple(kwargs[k] for k in map_obj._posarg_keys)
-> 1031             return key,map_obj[key]
   1032 
   1033         def apply(element,**kwargs):

~\Anaconda3\lib\site-packages\holoviews\core\spaces.py in __getitem__(self,**kwargs)
   1041         def dynamic_operation(*key,**kwargs):
   1042             key,kwargs)
-> 1043             return apply(obj,**kwargs)
   1044 
   1045         operation = self.p.operation

~\Anaconda3\lib\site-packages\holoviews\util\__init__.py in apply(element,**kwargs)
   1033         def apply(element,**kwargs):
   1034             kwargs = dict(util.resolve_dependent_kwargs(self.p.kwargs),**kwargs)
-> 1035             processed = self._process(element,key,kwargs)
   1036             if (self.p.link_dataset and isinstance(element,Dataset) and
   1037                 isinstance(processed,Dataset) and processed._dataset is None):

~\Anaconda3\lib\site-packages\holoviews\util\__init__.py in _process(self,element,kwargs)
   1015         elif isinstance(self.p.operation,Operation):
   1016             kwargs = {k: v for k,v in kwargs.items() if k in self.p.operation.param}
-> 1017             return self.p.operation.process_element(element,**kwargs)
   1018         else:
   1019             return self.p.operation(element,**kwargs)

~\Anaconda3\lib\site-packages\holoviews\core\operation.py in process_element(self,**params)
    192             self.p = param.ParamOverrides(self,params,193                                           allow_extra_keywords=self._allow_extra_keywords)
--> 194         return self._apply(element,key)
    195 
    196 

~\Anaconda3\lib\site-packages\holoviews\core\operation.py in _apply(self,key)
    139             if not in_method:
    140                 element._in_method = True
--> 141         ret = self._process(element,key)
    142         if hasattr(element,'_in_method') and not in_method:
    143             element._in_method = in_method

~\Anaconda3\lib\site-packages\holoviews\operation\datashader.py in _process(self,key)
   1496 
   1497     def _process(self,key=None):
-> 1498         agg = rasterize._process(self,key)
   1499         shaded = shade._process(self,agg,key)
   1500         return shaded

~\Anaconda3\lib\site-packages\holoviews\operation\datashader.py in _process(self,key)
   1475                                        if k in transform.param})
   1476             op._precomputed = self._precomputed
-> 1477             element = element.map(op,predicate)
   1478             self._precomputed = op._precomputed
   1479 

~\Anaconda3\lib\site-packages\holoviews\core\data\__init__.py in pipelined_fn(*args,**kwargs)
    203 
    204             try:
--> 205                 result = method_fn(*args,**kwargs)
    206                 if PipelineMeta.disable:
    207                     return result

~\Anaconda3\lib\site-packages\holoviews\core\data\__init__.py in map(self,**kwargs)
   1220 
   1221     def map(self,**kwargs):
-> 1222         return super(Dataset,self).map(*args,**kwargs)
   1223     map.__doc__ = LabelledData.map.__doc__
   1224 

~\Anaconda3\lib\site-packages\holoviews\core\dimension.py in map(self,map_fn,specs,clone)
    708             return deep_mapped
    709         else:
--> 710             return map_fn(self) if applies else self
    711 
    712 

~\Anaconda3\lib\site-packages\holoviews\core\operation.py in __call__(self,**kwargs)
    212             elif ((self._per_element and isinstance(element,Element)) or
    213                   (not self._per_element and isinstance(element,ViewableElement))):
--> 214                 return self._apply(element)
    215         elif 'streams' not in kwargs:
    216             kwargs['streams'] = self.p.streams

~\Anaconda3\lib\site-packages\holoviews\core\operation.py in _apply(self,key)
    468 
    469         dfdata = PandasInterface.as_dframe(data)
--> 470         agg = getattr(cvs,glyph)(dfdata,x.name,y.name,agg_fn)
    471         if 'x_axis' in agg.coords and 'y_axis' in agg.coords:
    472             agg = agg.rename({'x_axis': x,'y_axis': y})

~\Anaconda3\lib\site-packages\datashader\core.py in line(self,source,x,y,axis,geometry,antialias)
    403                            format(agg))
    404                 warnings.warn(message)
--> 405         return bypixel(source,self,glyph,agg)
    406 
    407     def area(self,agg=None,axis=0,y_stack=None):

~\Anaconda3\lib\site-packages\datashader\core.py in bypixel(source,canvas,agg)
   1211     with np.warnings.catch_warnings():
   1212         np.warnings.filterwarnings('ignore',r'All-NaN (slice|axis) encountered')
-> 1213         return bypixel.pipeline(source,schema,agg)
   1214 
   1215 

~\Anaconda3\lib\site-packages\datashader\utils.py in __call__(self,head,*rest,**kwargs)
    107         typ = type(head)
    108         if typ in lk:
--> 109             return lk[typ](head,**kwargs)
    110         for cls in getmro(typ)[1:]:
    111             if cls in lk:

~\Anaconda3\lib\site-packages\datashader\data_libraries\pandas.py in pandas_pipeline(df,summary)
     15 @bypixel.pipeline.register(pd.DataFrame)
     16 def pandas_pipeline(df,summary):
---> 17     return glyph_dispatch(glyph,df,summary)
     18 
     19 

~\Anaconda3\lib\site-packages\datashader\utils.py in __call__(self,**kwargs)
    110         for cls in getmro(typ)[1:]:
    111             if cls in lk:
--> 112                 return lk[cls](head,**kwargs)
    113         raise TypeError("No dispatch for {0} type".format(typ))
    114 

~\Anaconda3\lib\site-packages\datashader\data_libraries\pandas.py in default(glyph,summary,cuda)
     43 
     44     bases = create((height,width))
---> 45     extend(bases,x_st + y_st,x_range + y_range)
     46 
     47     return finalize(bases,~\Anaconda3\lib\site-packages\datashader\glyphs\line.py in extend(aggs,vt,bounds,plot_start)
     71             do_extend(
     72                 sx,tx,sy,ty,xmin,xmax,ymin,ymax,---> 73                 xs,ys,plot_start,*aggs_and_cols
     74             )
     75 

~\Anaconda3\lib\site-packages\numba\dispatcher.py in _compile_for_args(self,**kws)
    399                 e.patch_message(msg)
    400 
--> 401             error_rewrite(e,'typing')
    402         except errors.UnsupportedError as e:
    403             # Something unsupported is present in the user code,add help info

~\Anaconda3\lib\site-packages\numba\dispatcher.py in error_rewrite(e,issue_type)
    342                 raise e
    343             else:
--> 344                 reraise(type(e),e,None)
    345 
    346         argtypes = []

~\Anaconda3\lib\site-packages\numba\six.py in reraise(tp,value,tb)
    666             value = tp()
    667         if value.__traceback__ is not tb:
--> 668             raise value.with_traceback(tb)
    669         raise value
    670 

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
Internal error at <numba.typeinfer.StaticGetItemConstraint object at 0x0000021D40ACEC88>.
tuple index out of range
[1] During: typing of static-get-item at C:\Users\HornLab\Anaconda3\lib\site-packages\datashader\glyphs\line.py (653)
Enable logging at debug level for details.

File "..\..\..\Anaconda3\lib\site-packages\datashader\glyphs\line.py",line 653:
def _xiaolinwu(i,*aggs_and_cols):
    <source elided>
    agg = aggs_and_cols[0]
    cols = aggs_and_cols[1]
    ^

[1] During: resolving callee type: type(cpudispatcher(<function _xiaolinwu at 0x0000021D2E0B98B8>))
[2] During: typing of call at <draw_segment> (33)

[3] During: resolving callee type: type(cpudispatcher(<function _xiaolinwu at 0x0000021D2E0B98B8>))
[4] During: typing of call at <draw_segment> (33)


File "<draw_segment>",line 33:
<source missing,REPL/exec in use?>

[1] During: resolving callee type: type(cpudispatcher(<function draw_segment at 0x0000021D4063DAF8>))
[2] During: typing of call at <perform_extend_line> (13)

[3] During: resolving callee type: type(cpudispatcher(<function draw_segment at 0x0000021D4063DAF8>))
[4] During: typing of call at <perform_extend_line> (13)


File "<perform_extend_line>",line 13:
<source missing,REPL/exec in use?>

[1] During: resolving callee type: type(cpudispatcher(<function perform_extend_line at 0x0000021D4063DE58>))
[2] During: typing of call at <extend_cpu> (10)

[3] During: resolving callee type: type(cpudispatcher(<function perform_extend_line at 0x0000021D4063DE58>))
[4] During: typing of call at <extend_cpu> (10)


File "<extend_cpu>",line 10:
<source missing,REPL/exec in use?>

如果我删除“datashade”线并仅绘制 Holoviews 曲线图,则它可以正常工作。但是如果它是一个 2500 万个点图,它会花费很长时间,这就是为什么我需要 Datashader:

import numpy as np,)))).opts(width = 1000)
curve

输出图:

enter image description here

关于什么可能导致此错误的任何想法?如果需要,我可以提供任何其他信息。

解决方法

您的 Datashader 代码在我的系统上运行良好:

enter image description here

也许您有一些旧版本,尤其是 Numba?