我尝试使用本教程https://holoviz.org/tutorial/Basic_Plotting.html在 hvPlot 中使用数据阴影,但使用个人数据。
我可以用df.hvplot.scatter(x='col1', y='col2', datashade=False)
n 行显示我的情节,但是当我尝试使用 datashade with 时df.hvplot.scatter(x='col1', y='col2', datashade=True)
,我有这个错误:
Invoked as dynamic_operation(height=300, scale=1.0, width=700, x_range=None, y_range=None)
WARNING:param.dynamic_operation: Callable raised "TypeError("Cannot cast array data from dtype('int64') to dtype('int32') according to the rule 'safe'")".
Invoked as dynamic_operation(height=300, scale=1.0, width=700, x_range=None, y_range=None)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~\Anaconda3\envs\holoviz-tutorial\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\envs\holoviz-tutorial\lib\site-packages\holoviews\core\dimension.py in _repr_mimebundle_(self, include, exclude)
1302 combined and returned.
1303 """
-> 1304 return Store.render(self)
1305
1306
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\core\options.py in render(cls, obj)
1393 data, metadata = {}, {}
1394 for hook in hooks:
-> 1395 ret = hook(obj)
1396 if ret is None:
1397 continue
~\Anaconda3\envs\holoviz-tutorial\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\envs\holoviz-tutorial\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\envs\holoviz-tutorial\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\envs\holoviz-tutorial\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\envs\holoviz-tutorial\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\envs\holoviz-tutorial\lib\site-packages\holoviews\plotting\renderer.py in components(self, obj, fmt, comm, **kwargs)
374 doc = Document()
375 with config.set(embed=embed):
--> 376 model = plot.layout._render_model(doc, comm)
377 if embed:
378 return render_model(model, comm)
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\panel\viewable.py in _render_model(self, doc, comm)
415 if comm is None:
416 comm = state._comm_manager.get_server_comm()
--> 417 model = self.get_root(doc, comm)
418
419 if config.embed:
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\panel\viewable.py in get_root(self, doc, comm)
640 """
641 doc = doc or _curdoc()
--> 642 root = self._get_model(doc, comm=comm)
643 self._preprocess(root)
644 ref = root.ref['id']
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\panel\layout.py in _get_model(self, doc, root, parent, comm)
118 if root is None:
119 root = model
--> 120 objects = self._get_objects(model, [], doc, root, comm)
121 props = dict(self._init_properties(), objects=objects)
122 model.update(**self._process_param_change(props))
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\panel\layout.py in _get_objects(self, model, old_objects, doc, root, comm)
108 else:
109 try:
--> 110 child = pane._get_model(doc, root, model, comm)
111 except RerenderError:
112 return self._get_objects(model, current_objects[:i], doc, root, comm)
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\panel\pane\holoviews.py in _get_model(self, doc, root, parent, comm)
225 plot = self.object
226 else:
--> 227 plot = self._render(doc, comm, root)
228
229 plot.pane = self
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\panel\pane\holoviews.py in _render(self, doc, comm, root)
284 kwargs = {}
285
--> 286 return renderer.get_plot(self.object, **kwargs)
287
288 def _cleanup(self, root):
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\plotting\bokeh\renderer.py in get_plot(self_or_cls, obj, doc, renderer, **kwargs)
71 combining the bokeh model with another plot.
72 """
---> 73 plot = super(BokehRenderer, self_or_cls).get_plot(obj, doc, renderer, **kwargs)
74 if plot.document is None:
75 plot.document = Document() if self_or_cls.notebook_context else curdoc()
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\plotting\renderer.py in get_plot(self_or_cls, obj, doc, renderer, comm, **kwargs)
209
210 # Initialize DynamicMaps with first data item
--> 211 initialize_dynamic(obj)
212
213 if not renderer:
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\plotting\util.py in initialize_dynamic(obj)
249 continue
250 if not len(dmap):
--> 251 dmap[dmap._initial_key()]
252
253
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\core\spaces.py in __getitem__(self, key)
1278 # Not a cross product and nothing cached so compute element.
1279 if cache is not None: return cache
-> 1280 val = self._execute_callback(*tuple_key)
1281 if data_slice:
1282 val = self._dataslice(val, data_slice)
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\core\spaces.py in _execute_callback(self, *args)
1052
1053 with dynamicmap_memoization(self.callback, self.streams):
-> 1054 retval = self.callback(*args, **kwargs)
1055 return self._style(retval)
1056
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\core\spaces.py in __call__(self, *args, **kwargs)
691
692 try:
--> 693 ret = self.callable(*args, **kwargs)
694 except KeyError:
695 # KeyError is caught separately because it is used to signal
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\util\__init__.py in dynamic_operation(*key, **kwargs)
983
984 def dynamic_operation(*key, **kwargs):
--> 985 key, obj = resolve(key, kwargs)
986 return apply(obj, *key, **kwargs)
987
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\util\__init__.py in resolve(key, kwargs)
976 elif isinstance(map_obj, DynamicMap) and map_obj._posarg_keys and not key:
977 key = tuple(kwargs[k] for k in map_obj._posarg_keys)
--> 978 return key, map_obj[key]
979
980 def apply(element, *key, **kwargs):
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\core\spaces.py in __getitem__(self, key)
1278 # Not a cross product and nothing cached so compute element.
1279 if cache is not None: return cache
-> 1280 val = self._execute_callback(*tuple_key)
1281 if data_slice:
1282 val = self._dataslice(val, data_slice)
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\core\spaces.py in _execute_callback(self, *args)
1052
1053 with dynamicmap_memoization(self.callback, self.streams):
-> 1054 retval = self.callback(*args, **kwargs)
1055 return self._style(retval)
1056
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\core\spaces.py in __call__(self, *args, **kwargs)
691
692 try:
--> 693 ret = self.callable(*args, **kwargs)
694 except KeyError:
695 # KeyError is caught separately because it is used to signal
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\util\__init__.py in dynamic_operation(*key, **kwargs)
984 def dynamic_operation(*key, **kwargs):
985 key, obj = resolve(key, kwargs)
--> 986 return apply(obj, *key, **kwargs)
987
988 operation = self.p.operation
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\util\__init__.py in apply(element, *key, **kwargs)
980 def apply(element, *key, **kwargs):
981 kwargs = dict(util.resolve_dependent_kwargs(self.p.kwargs), **kwargs)
--> 982 return self._process(element, key, kwargs)
983
984 def dynamic_operation(*key, **kwargs):
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\util\__init__.py in _process(self, element, key, kwargs)
962 elif isinstance(self.p.operation, Operation):
963 kwargs = {k: v for k, v in kwargs.items() if k in self.p.operation.param}
--> 964 return self.p.operation.process_element(element, key, **kwargs)
965 else:
966 return self.p.operation(element, **kwargs)
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\core\operation.py in process_element(self, element, key, **params)
170 self.p = param.ParamOverrides(self, params,
171 allow_extra_keywords=self._allow_extra_keywords)
--> 172 return self._apply(element, key)
173
174
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\core\operation.py in _apply(self, element, key)
130 element_pipeline = getattr(element, '_pipeline', None)
131
--> 132 ret = self._process(element, key)
133 for hook in self._postprocess_hooks:
134 ret = hook(self, ret, **kwargs)
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\operation\datashader.py in _process(self, element, key)
1435 def _process(self, element, key=None):
1436 agg = rasterize._process(self, element, key)
-> 1437 shaded = shade._process(self, agg, key)
1438 return shaded
1439
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\holoviews\operation\datashader.py in _process(self, element, key)
1267 return RGB(img, **params)
1268 else:
-> 1269 img = tf.shade(array, **shade_opts)
1270 return RGB(self.uint32_to_uint8_xr(img), **params)
1271
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\datashader\transfer_functions\__init__.py in shade(agg, cmap, color_key, how, alpha, min_alpha, span, name, color_baseline)
509
510 if agg.ndim == 2:
--> 511 return _interpolate(agg, cmap, how, alpha, span, min_alpha, name)
512 elif agg.ndim == 3:
513 return _colorize(agg, color_key, how, alpha, span, min_alpha, name, color_baseline)
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\datashader\transfer_functions\__init__.py in _interpolate(agg, cmap, how, alpha, span, min_alpha, name)
240 with np.errstate(invalid="ignore", divide="ignore"):
241 # Transform data (log, eq_hist, etc.)
--> 242 data = interpolater(data, mask)
243
244 # Transform span
~\Anaconda3\envs\holoviz-tutorial\lib\site-packages\datashader\transfer_functions\__init__.py in eq_hist(data, mask, nbins)
171 if data2.dtype.kind == 'u':
172 data2 = data2.astype('i8')
--> 173 hist = np.bincount(data2.ravel())
174 bin_centers = np.arange(len(hist))
175 idx = int(np.nonzero(hist)[0][0])
<__array_function__ internals> in bincount(*args, **kwargs)
TypeError: Cannot cast array data from dtype('int64') to dtype('int32') according to the rule 'safe'
我的所有数据都在我的数据框中的 float64 中,并且我在 5 行数据而不是 38k+ 时得到相同的错误。我的 5 行如下所示:
col1 col2
0 14.455556 72.211111
1 2.561111 11.222222
2 3.705556 2050.000000
3 3.816667 80.433333
4 18.919444 1993.586111
5 5.238889 249.433333
我错过了什么?我尝试过像示例这样的索引,以及日期时间中的索引。