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

I saw that it is possible to do it during the demo: https://youtu.be/2Tt0i823-ec?t=769
There, the presenter has a huge dataset, and can quickly zoom in by selecting a rectangle with the mouse.
I also saw the "Interactive Widgets" section of the tutorial: https://docs.vaex.io/en/latest/tutorial.html#Interactive-widgets
However, I was not able to easily replicate that setup. What are the minimal steps to achieve it?
On Ubuntu 19.04 vaex 2.0.2, I have tried:
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
Then I created a notebook and paste in the 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')
but all I get is no graph and the message:
Plot2dDefault(w=None, what='count(*)', x='x', y='y', z=None)
If instead I do:
df.plot(df.x, df.y, f='log1p')
then I do get an plot, but it is just a non-interactive image.
I also tried to git clone the notebook that is the source of the read the docs page: https://github.com/vaexio/vaex/blob/0247f0673c5c0473001b0b66adcbc716560536aa/docs/source/tutorial.ipynb but the result was the same.
My motivation is to find a plotting program that can handle large number of points as mentioned at: Large plot: ~20 million samples, gigabytes of data

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.

Related

Cannot import name 'to_html' from 'pandas_profiling.report' using JupyterLab

I'm new using Jupyter Lab and Pandas profiling.
I'm trying to install and import and install Pandas Profiling in a jupyter notebook. I'm able to install pandas collab using pip, but unable to import the library. The error says I cannot import name 'to_html' from 'pandas_profiling.report'.
Here's the code and the error.
Funny thing is: I also tried to run the notebook in Google Colab, but I got a different but similar error:
ImportError: cannot import name 'PandasProfiling' from 'pandas_profiling' (/usr/local/lib/python3.8/dist-packages/pandas_profiling/__init__.py)
I already tried to use Jupyter Lab and Jupyter Notebook from Anaconda and Google Colab to see if it works, but no look.
conda install -c conda-forge pandas-profiling
See this question.
from pandas_profiling import ProfileReport
https://pandas-profiling.ydata.ai/docs/master/pages/getting_started/quickstart.html
PandasProfiling object does not exist.

ImportError: IProgress not found. Please update jupyter and ipywidgets although it is installed

I am using jupyter notebook and installed.
ipywidgets==7.4.2 widgetsnbextension pandas-profiling=='.0.0
and also I ran:
!jupyter nbextension enable --py widgetsnbextension
but when running:
from pandas_profiling import ProfileReport
profile = ProfileReport(df, title="Pandas Profiling Report", explorative=True)
profile.to_widgets()
I get the error:
ImportError: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
Any idea why?
Tried proposed solutions.
I tried everything you mentioned in a new environment using conda and I had another issue related to the version of ipywidgets (a bug found in Github with comments saying that got solved after using last version). I solved the problem I had installing last version of ipywidgets. Here is my process:
Create a new environment using conda (I use miniconda):
conda create --name teststackoverflow python=3.7
Activate new environment:
conda activate teststackoverflow
Install jupyter:
pip install jupyter
Install all the libraries without specific versions to get the last ones:
pip install ipywidgets widgetsnbextension pandas-profiling
Run jupyter notebook in the console to turn on the notebooks server and create a new notebook.
Run this line in a new cell:
!jupyter nbextension enable --py widgetsnbextension
With the result:
Enabling notebook extension jupyter-js-widgets/extension...
- Validating: OK
Run some sample code to define df:
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [1, 2, 3, 4]})
Run the code you provided:
from pandas_profiling import ProfileReport
profile = ProfileReport(df, title="Pandas Profiling Report", explorative=True)
profile.to_widgets()
Final output looks good:
this had worked for me (for all of you who prefer pip instead of conda..)
in your virtualenv run
pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension
or, if you prefer to run it in your notebook
!pip install ipywidgets
!jupyter nbextension enable --py widgetsnbextension
and in your notebook add
from ipywidgets import FloatProgress
Installing ipywidgets and building Jupyter Lab did the trick for me.
Make sure you activate the correct conda environment
Install ipywidgets: conda install -c conda-forge ipywidgets
To build Jupyter Lab, you need to have nodejs > 12.0.0 installed. Check the latest version number from Anaconda website and install nodejs specifying the package number e.g. conda install -c conda-forge nodejs=16.6.1
Stop Jupyter Lab
Build Juyter Lab: jupyter lab build
Start Jupyter Lab
I ran into the same error within the jupyter lab and I just installed ipywidgets using conda install -c conda-forge ipywidgets command.
I ran into the same error. On M1 mac, I change from tqdm.notebook import tqdm as tqdm to from tqdm import tqdm. Hope it helps. Original post: https://github.com/CosmiQ/solaris/issues/392#issuecomment-759238485

Jupyter notebook can not import module installed in the same environment

I have created a virtual environment using conda and then I have installed tensorflow within this environment. I can import it when I run interactive python shell. However, I can not import the tensorflow module within jupyter notebook.
You need install Jupyter into same environment. Activate the environment with tensorflow and:
conda install jupyter
to make sure you use the corresponding jupyter start with:
python -m jupyter notebook
You probably have two installations of python on your box. When you run your notebook, run the following:
import sys
print(sys.path)
and then
import os
print(os.environ['PATH'])
print(os.environ['PYTHONPATH'])
Make sure they are pointing the location where you installed tensorflow. You can check where you installed tensorflow by running from the command line:
pip show -f tensorflow
or from the shell by running:
import tensorflow
tensorflow.__file__
As David said, you probably have two installation of python on you machine,
check sys.path from your environment in terminal and from your notebook, they should ideally point to your local environment.
To use jupyter notebook from your local environment install it and run kernel using
python -m jupyter notebook

ipython cannot search matplotlib while using tensorflow and jupyter also has import error

I am using python 2.7 in Ubuntu and recently updated tensorflow 0.12.1.
I installed jupyter today for my sample code of tf and I need to use matplotlib. It does not find module name matplotlib and ipython in tensorflow has same error.
1. How can I set path in virtualenv or ipython or jupyter?
After activate tensorflow, I need to use jupyter notebook.
This below in the script for error does not work.
import sys
sys.path.append('my/path/to/module/folder')
import module-of-interest
2. other information: My environments are below.
mickyefromsd#DEKSTOP~$source ~/tensorflow/bin/activate
When I find matplotlib by python script under TF condition and before TF activation, it has below;
/usr/lib/python2.7/dist-packages/matplotlib/
When I type 'which ipython', it has below (not by /usr/bin/ipython) ;
/home/mickeyfromd/tensorflow/bin/ipython
Btw, /tensorflow/lib/python2.7/site-packages/ it has ipython and jupyter.
(not in the same path of matplotlib)
3. My ipython under TF cannot find my existing matplotlib.
(tensorflow) mickeyfromd#DK-DESKTOP:~$ ipython
Python 2.7.11+ (default, Apr 17 2016, 14:00:29)
In [1]: import matplotlib ImportError: No module named matplotlib
4. I wanted to setup virtualenv, so I just run this
I followed this site. site:http://help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs
(tensorflow) mickeyfromd#ipython kernelspec install-self --user
.....
Installed kernelspec python2 in /home/mickeyfromd/.local/share/jupyter/kernels/python2
(tensorflow) mickeyfromd#DK-DESKTOP:~$
I cannot move the the folder (in the second step)
How can I make ipython to have path for Matplotlib?
That import error is due to change in environment of the jupyter notebook. You might have installed the packages in one environment and you are running the jupyter notebook in another environment.
I have got two environments (envs) in my Anaconda folder ( I have Anaconda3 folder to be specific ).
(windows key+cmd ) -> open the windows command prompt run as administrator.
Activate (name of the environment) -> eg.: activate tensorflow-gpu
Start installing packages using conda install
Note: For each environment you need to install all the packages you want to use, separately using the same process. This solution is for windows users, might work for linux users not sure though.
Additionally to make sure your conda environment is up to date run:
conda update conda
conda update anaconda
check this out : https://pradyumnamajumder.wordpress.com/2017/09/30/solution-to-the-python-packages-import-error-in-jupyter/

%matplotlib inline does not show any plot on jupyter notebook

matplotlib.pyplot takes a long time to run and finally no plot shows on the screen
But matplotlib.back_end() gives the following
u'TkAgg'
Can someone suggest a solution?
NOTE: I installed matplotlib using pip install matplotlib
I had a similar problem working with jupyter notebook on a Mac OSX 10.10.5
In the end I fixed it by reinstalling IPython and dependencies with the command
pip install -U --force-reinstall numpy matplotlib pyzmq jinja2 ipython