3

我在演示期间看到可以做到这一点:https ://youtu.be/2Tt0i823-ec?t=769

在那里,演示者有一个巨大的数据集,并且可以通过用鼠标选择一个矩形来快速放大。

我还看到了教程的“交互式小部件”部分:https ://docs.vaex.io/en/latest/tutorial.html#Interactive-widgets

但是,我无法轻松复制该设置。实现它的最小步骤是什么?

在 Ubuntu 19.04 vaex 2.0.2 上,我尝试过:

python3 -m pip install --user 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

然后我创建了一个笔记本并粘贴在笔记本中:

import vaex
import vaex.jupyter
import numpy as np
import pylab as plt
%matplotlib inline
df = vaex.example()
df.plot_widget(df.x, df.y, f='log1p', backend='bqplot')

但我得到的只是没有图表和消息:

Plot2dDefault(w=None, what='count(*)', x='x', y='y', z=None)

相反,如果我这样做:

df.plot(df.x, df.y, f='log1p')

然后我确实得到了一个情节,但这只是一个非交互式图像。

我还尝试 git 克隆作为阅读文档页面来源的笔记本:https ://github.com/vaexio/vaex/blob/024​​7f0673c5c0473001b0b66adcbc716560536aa/docs/source/tutorial.ipynb但结果是相同的。

我的动机是找到一个可以处理大量点的绘图程序,如下所述:Large plot: ~20M samples, GB data

4

2 回答 2

3

利用virtualenv

不知道为什么,但这解决了它。我认为这是因为 Jupyter 可执行文件位于 Python 2 上并且找不到 Python 3 扩展。

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

并在一个新笔记本中:

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

现在我看到了带有缩放功能的交互式小部件!

在此处输入图像描述

版本:

pandas==0.25.0
scipy==1.3.0
vaex==2.0.2
vaex-jupyter==0.3.0
于 2019-08-08T09:00:10.107 回答
2

Jupyter小部件存在前端代码和内核代码,内核代码(本例中为Python)通常不是问题,如果你可以导入例如ipywidgets模块,你应该没问题。

最大的问题是确保前端(经典笔记本或 Jupyter 实验室)加载了匹配的 javascript 库。假设您使用的是经典笔记本,调试方法如下:

由于 ipywidgets 库的 javascript 代码是使用 nbextension 机制添加到前端的,因此您可以检查是否所有库都已启用并验证使用

$ jupyter nbextension list

这应该显示所有绿色的“OK”和“启用”(除非您明确禁用它)。

如果没有正确安装,您可能需要安装前端代码,例如:

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

如果由于某种原因未自动启用扩展(旧版本的笔记本),请运行:

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

如果事情不工作,你应该测试哪个库不工作,例如,从 ipywidgets 开始:

import ipywidgets as widgets
widget.FloatSlider()

如果这没有显示滑块,那么您就有麻烦了。继续使用其他库,看看它何时失败。当它失败时,检查 javascript 控制台(google that for your browser)是否有错误消息,看看你是否从中得到提示。

最后,请确保您使用的是现代浏览器,Internet Explorer 将不再适用,它太旧了。我推荐 Chrome/Chromium 或 Firefox。

于 2019-08-08T07:35:21.693 回答