Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to add a colorbar to hv.Scatter3D is broken #5093

Closed
mycarta opened this issue Sep 30, 2021 · 3 comments
Closed

Option to add a colorbar to hv.Scatter3D is broken #5093

mycarta opened this issue Sep 30, 2021 · 3 comments
Assignees
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@mycarta
Copy link

mycarta commented Sep 30, 2021

ALL software version info

I am running the code below using Jupyter notebook
with holoviews version 1.14.3

Description of expected behavior and the observed behavior

The code below is working as expected (see screen capture). But when I modify the plotting function to add the colorbar I get the error listed at the bottom.

sc = hv.Scatter3D(dataset3d).opts(opts.Scatter3D(azimuth=az, elevation=elev, s=200, 
                                                     color = 'value', cmap = 'viridis', fig_size=200)).opts(colorbar=True)

Screen Shot 2021-09-30 at 4 41 44 PM

Complete, minimal, self-contained example code that reproduces the issue

# Import libraries
import numpy as np
import pandas as pd
import holoviews as hv
from holoviews import dim, opts
import panel as pn
hv.extension('matplotlib')

# Make some fake 3D points
arr =([55,45,33,1], 
        [66,55,66,2], 
        [77,65,99,3],
        [88,75,132,4],
        [99,75,165,5],
        [111,85,198,6]
     )
temp = pd.DataFrame(arr, columns=['X','Y','Z','C'])

# plotting function
def plot3d(az, elev):
    dataset3d = hv.Dataset((temp['X'], temp['Y'], 
                 temp['Z'], temp['C']),['x', 'y', 'z'], 'value')
    sc = hv.Scatter3D(dataset3d).opts(opts.Scatter3D(azimuth=az, elevation=elev, s=200, 
                                                     color = 'value', cmap = 'viridis', fig_size=400))
    return sc

# Panel stuff
azlider = pn.widgets.IntSlider(name='azimuth', value=60, start=-180, end=180)
elevaider = pn.widgets.IntSlider(name='elevation', value=20, start=0, end=90)
widgets = pn.Column(azlider, elevaider)
reactive_plot = pn.bind(plot3d, azlider, elevaider)
app = pn.Row(reactive_plot, widgets, sizing_mode='stretch_width')
app

Traceback in the Jupyter notebook

_---------------------------------------------------------------------------
TypeError 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\panel\viewable.py in repr_mimebundle(self, include, exclude)
571 doc = _Document()
572 comm = state._comm_manager.get_server_comm()
--> 573 model = self._render_model(doc, comm)
574 ref = model.ref['id']
575 manager = CommManager(comm_id=comm.id, plot_id=ref)

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

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

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

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

~\Anaconda3\lib\site-packages\panel\pane\base.py in _get_model(self, doc, root, parent, comm)
408 if ref in self._models:
409 self._cleanup(root)
--> 410 model = self._inner_layout._get_model(doc, root, parent, comm)
411 if root is None:
412 ref = model.ref['id']

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

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

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

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

~\Anaconda3\lib\site-packages\holoviews\plotting\renderer.py in get_plot(self_or_cls, obj, doc, renderer, comm, **kwargs)
241 init_key = tuple(v if d is None else d for v, d in
242 zip(plot.keys[0], defaults))
--> 243 plot.update(init_key)
244 else:
245 plot = obj

~\Anaconda3\lib\site-packages\holoviews\plotting\mpl\plot.py in update(self, key)
249 def update(self, key):
250 if len(self) == 1 and ((key == 0) or (key == self.keys[0])) and not self.drawn:
--> 251 return self.initialize_plot()
252 return self.getitem(key)
253

~\Anaconda3\lib\site-packages\holoviews\plotting\mpl\plot.py in wrapper(self, *args, **kwargs)
45 def wrapper(self, *args, **kwargs):
46 with _rc_context(self.fig_rcparams):
---> 47 return f(self, *args, **kwargs)
48 return wrapper
49

~\Anaconda3\lib\site-packages\holoviews\plotting\mpl\element.py in initialize_plot(self, ranges)
522 Stream.trigger(trigger)
523
--> 524 return self._finalize_axis(self.keys[-1], element=element, ranges=ranges,
525 **axis_kwargs)
526

~\Anaconda3\lib\site-packages\holoviews\plotting\mpl\chart3d.py in _finalize_axis(self, key, **kwargs)
85 else:
86 axis.set_facecolor(self.bgcolor)
---> 87 return super(Plot3D, self)._finalize_axis(key, **kwargs)
88
89

~\Anaconda3\lib\site-packages\holoviews\plotting\mpl\element.py in _finalize_axis(self, key, element, title, dimensions, ranges, xticks, yticks, zticks, xlabel, ylabel, zlabel)
191
192 if not subplots and not self.drawn:
--> 193 self._finalize_artist(element)
194
195 self._execute_hooks(element)

~\Anaconda3\lib\site-packages\holoviews\plotting\mpl\element.py in _finalize_artist(self, element)
774 dims = [h for k, h in self.handles.items() if k.endswith('color_dim')]
775 for d in dims:
--> 776 self._draw_colorbar(element, d)
777
778

~\Anaconda3\lib\site-packages\holoviews\plotting\mpl\chart3d.py in _draw_colorbar(self, element, dim, redraw)
102 dim = element.get_dimension(2)
103 elif not isinstance(dim, Dimension):
--> 104 dim = element.get_dimension(dim)
105 label = dim.pprint_label
106 cbar = fig.colorbar(artist, shrink=0.7, ax=ax)

~\Anaconda3\lib\site-packages\holoviews\core\dimension.py in get_dimension(self, dimension, default, strict)
960 """
961 if dimension is not None and not isinstance(dimension, (int, basestring, Dimension)):
--> 962 raise TypeError('Dimension lookup supports int, string, '
963 'and Dimension instances, cannot lookup '
964 'Dimensions using %s type.' % type(dimension).name)

TypeError: Dimension lookup supports int, string, and Dimension instances, cannot lookup Dimensions using dim type.

Row(sizing_mode='stretch_width')
[0] ParamFunction(function)
[1] Column
[0] IntSlider(end=180, name='azimuth', start=-180, value=60, value_throttled=60)
[1] IntSlider(end=90, name='elevation', value=20, value_throttled=20)_

@jbednar
Copy link
Member

jbednar commented Oct 1, 2021

Thanks for filing the issue. I can get that same error from the stock example if I add colorbar=True:

import numpy as np
import holoviews as hv
from holoviews import dim, opts
hv.extension('matplotlib')

y,x = np.mgrid[-5:5, -5:5] * 0.1
heights = np.sin(x**2+y**2)
s = hv.Scatter3D((x.flat, y.flat, heights.flat)).opts(
    opts.Scatter3D(azimuth=40, elevation=20, color='z', s=50, cmap='fire', colorbar=True))
s

Seems like a bug to me, since the error doesn't seem related to showing a colorbar.

@jlstevens jlstevens added the type: bug Something isn't correct or isn't working label Nov 8, 2021
@jlstevens jlstevens added this to the v2.0 milestone Nov 8, 2021
@philippjfr philippjfr modified the milestones: v2.0, 1.14.7 Nov 16, 2021
@philippjfr
Copy link
Member

Duplicate of #4891

@philippjfr philippjfr marked this as a duplicate of #4891 Nov 16, 2021
@jbednar
Copy link
Member

jbednar commented Nov 16, 2021

And thus presumably fixed by #5137 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

No branches or pull requests

4 participants