How to do interactive 2D scatter plot zoom / point selection in Vaex?

你离开我真会死。 提交于 2019-12-06 07:30:37

Use virtualenv

Not sure why, but this fixed it. I think it is because the Jupyter executable was on Python 2 and could not find Python 3 extensions.

virtualenv --python=python3 .venv
. .venv/bin/activate
python3 -m pip install vaex scipy pandas vaex-jupyter
jupyter nbextension enable --py widgetsnbextension
jupyter nbextension enable --py bqplot
jupyter nbextension enable --py ipyvolume
jupyter nbextension enable --py ipympl
jupyter nbextension enable --py ipyleaflet
jupyter nbextension enable --py ipyvuetify
jupyter notebook

and inside a new notebook:

import vaex
df = vaex.example()
df.plot_widget(df.x, df.y, f='log1p', backend='bqplot')

and now I see the interactive widget with zoom!

Versions:

pandas==0.25.0
scipy==1.3.0
vaex==2.0.2
vaex-jupyter==0.3.0

Jupyter widgets exist of front-end code and kernel code, the kernel code (Python in this case) is usually not the problem, if you can import for instance the ipywidgets module, you should be fine.

The biggest problem is making sure the front-end (classical notebook or Jupyter lab) has the matching javascript libraries loaded. Assuming you are working from the classical notebook, the way to debug is as following:

Since the javascript code of ipywidgets libraries are added to the frontend using the nbextension mechanism, you can check if all libraries are enabled and validated using

$ jupyter nbextension list

Which should show all green 'OK' and 'enabled' (unless you explicitly disabled it).

If not properly installed, you may want to do an installation of the front-end code, e.g.:

$ jupyter nbextension install --py --symlink --sys-prefix ipywidgets
$ jupyter nbextension install --py --symlink --sys-prefix ipyvuetify

If for some reason the extension is not automatically enabled (older versions of the notebook), run:

$ jupyter nbextension enable bqplot --py --sys-prefix
$ jupyter nbextension enable ipyvuetify --py --sys-prefix

If things aren't working, you should test which library isn't working, for instance, start with ipywidgets:

import ipywidgets as widgets
widget.FloatSlider()

If this doesn't show a slider, you are in trouble. Continue with the other libraries, and see when it fails. When it fails, check the javascript console (google that for your browser) for error messages, and see if you get hints from that.

Lastly, make sure you use a modern browser, Internet Explorer won't cut it anymore, it's too old. I recommend Chrome/Chromium or Firefox.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!