Skip to content

Instantly share code, notes, and snippets.

@alexpawlowski
Created November 14, 2017 16:10
Show Gist options
  • Save alexpawlowski/e7b72be19f6978243669b23cfc85e949 to your computer and use it in GitHub Desktop.
Save alexpawlowski/e7b72be19f6978243669b23cfc85e949 to your computer and use it in GitHub Desktop.
Helpful tip on getting jupyter lab up and running with matplotlib
LastUpdated versions
2017-11-14
python
3.6.3
jupyter
1.0.0
ipympl
0.0.12
ipywidgets
7.0.0
platform
win64_10

While Jupyter Lab is still in alpha and subject to change often (beta coming soon), it's interface is incredibly useful over the standard notebook interface. My one trouble has been using matplotlib for an interactive viewer of image slices that I can move through using an IntSlider. This workflow is incredibly useful in a notebook environment, and would like to have to save with jupyter lab.

After some scouring of the internet and recent updates: here is the best case to get everything set up properly.

After installing ipywidgets, jupyter from anaconda and installing the latest release of jupyterlab from conda-forge, also install ipympl from conda-forge. There is an important setting that you need to be aware of, as Jupyter Lab by default limits javascript execution (probably for safety reasons) to extensions within jupyter's ipywidgets.

If you want the slick interactive goodness of matplotlib you might be accustomed to with Qt implementations when running python from an ide or command line, matplotlib added their %matplotlib notebook keyword arguments for notebooks.

In Jupyter Lab however, % matplotlib ipympl needs to be used instead of %matplotlib notebook, I believe because of the javascript running issue that is okay in a notebook environment but not okay in the Jupyter Lab instance.

Install ipympl

To install ipympl with conda: source

$ conda install -c conda-forge ipympl 
$ # If using the Notebook
$ conda install -c conda-forge widgetsnbextension
$ # If using JupyterLab
$ conda install nodejs
$ jupyter labextension install @jupyter-widgets/jupyterlab-manager

I will try to update this gist as new versions come out. Eventually this gist will lose purpose probably as it's more integrated in with jupyter lab's subsequent releases or better covered.

Configuration

jupyter                   1.0.0            py36_3    anaconda
jupyter_client            5.1.0            py36      anaconda
jupyter_console           5.2.0            py36      anaconda
jupyter_core              4.3.0            py36      anaconda
jupyterlab                0.29.1           py36_0    conda-forge
jupyterlab_launcher       0.5.5            py36_0    conda-forge
widgetsnbextension        3.0.2            py36      anaconda
ipykernel                 4.6.1            py36      anaconda
ipympl                    0.0.12           py36_1    conda-forge
ipython                   6.1.0            py36      anaconda
ipython_genutils          0.2.0            py36      anaconda
ipywidgets                7.0.0            py36      anaconda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment