widgetti / ipyvolume

3d plotting for Python in the Jupyter notebook based on IPython widgets using WebGL
MIT License
1.95k stars 236 forks source link

ipyvolume.pylab.scatter: KeyError Traceback (most recent call last) #177

Open swiss-knight opened 6 years ago

swiss-knight commented 6 years ago

When trying to run this notebook: https://github.com/rockestate/point-cloud-processing/blob/master/notebooks/point-cloud-processing.ipynb

I encountered this error when reaching this command:

# Color ground in grey
df['ground'] = df['Classification']!=1
#ground = p3.scatter(df.loc[df['ground'],'Y'], df.loc[df['ground'],'Z'], df.loc[df['ground'],'X'], color='red', size=.2)
non_ground = p3.scatter(df.loc[~df['ground'],'Y'], df.loc[~df['ground'],'Z'], df.loc[~df['ground'],'X'], color='red', size=.2)

resulting in such error message:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-17-98903417dd52> in <module>()
      3 p3.scatter(df.loc[~df['ground'],'Y'],
      4            df.loc[~df['ground'],'Z'],
----> 5            df.loc[~df['ground'],'X'])

/usr/local/lib/python3.5/dist-packages/ipyvolume/pylab.py in scatter(x, y, z, color, size, size_selected, color_selected, marker, selection, grow_limits, **kwargs)
    417     fig = gcf()
    418     if grow_limits:
--> 419         _grow_limits(x, y, z)
    420     s = ipv.Scatter(x=x, y=y, z=z, color=color, size=size,
    421                     color_selected=color_selected, size_selected=size_selected,

/usr/local/lib/python3.5/dist-packages/ipyvolume/pylab.py in _grow_limits(x, y, z)
    164 def _grow_limits(x, y, z):
    165     fig = gcf()
--> 166     xlim(*_grow_limit(fig.xlim, x))
    167     ylim(*_grow_limit(fig.ylim, y))
    168     zlim(*_grow_limit(fig.zlim, z))

/usr/local/lib/python3.5/dist-packages/ipyvolume/pylab.py in _grow_limit(limits, values)
    147     else:
    148         try:
--> 149             values[0]  # test if scalar
    150         except TypeError:
    151             newvmin = values

/usr/local/lib/python3.5/dist-packages/pandas/core/series.py in __getitem__(self, key)
    765         key = com._apply_if_callable(key, self)
    766         try:
--> 767             result = self.index.get_value(self, key)
    768 
    769             if not is_scalar(result):

/usr/local/lib/python3.5/dist-packages/pandas/core/indexes/base.py in get_value(self, series, key)
   3116         try:
   3117             return self._engine.get_value(s, k,
-> 3118                                           tz=getattr(series.dtype, 'tz', None))
   3119         except KeyError as e1:
   3120             if len(self) > 0 and self.inferred_type in ['integer', 'boolean']:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

KeyError: 0

I cannot figure out why and it seems related to pandas as well, so please let me know if it's better to post an issue for this latter package instead. :)

Here are my pandas and ipyvolume versions:

print("ipyvolume.__version__: {}".format(ipyvolume.__version__))
print("pandas.__version__: {}".format(pd.__version__))
ipyvolume.__version__: 0.5.1
pandas.__version__: 0.23.4

I am using Ubuntu 16.04 with Python 3.5.2.

maartenbreddels commented 6 years ago

Try passing grow_limits=False to scatter, I don't 'offically' support pandas, make sure you pass a numpy array to ipyvolume, that should always work.

michaelaye commented 5 years ago

Tried, but didn't work, as points stayed out of view. Downcasting to numpy worked, thanks!