Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jupyterlab interactive plot

I'm getting into using Jupyterlab from Jupyter notebooks. In notebooks I used to use:

import matplotlib.pyplot as plt %matplotlib notebook plt.figure() x = [1,2,3] y = [4,5,6] plt.plot(x,y) 

for interactive plots. Which now gives me (in jupyterlab):

JavaScript output is disabled in JupyterLab 

I have also tried the magic (with jupyter-matplotlib installed):

%matplotlib ipympl 

But that just returns:

FigureCanvasNbAgg() 

Inline plots:

%matplotlib inline 

work just fine, but I want interactive plots.

like image 586
Albatross Avatar asked May 03 '18 07:05

Albatross


People also ask

Can Jupyter notebooks be interactive?

Jupyter Notebook has support for many kinds of interactive outputs, including the ipywidgets ecosystem as well as many interactive visualization libraries.

Can you make matplotlib interactive?

The plot widget can be resized by the UI.The ipyml backend enables interactivity in matplotlib and all the libraries built on top of matplotlib like Pandas, Geopandas, Seaborn, etc.

Do We Still Need %Matplotlib inline?

The only reason %matplotlib inline is used is to render any matplotlib diagrams even if the plt. show() function is not called. However, even if %matplotlib inline is not used, Jupyter will still display the Matplotlib diagram as an object, with something like matplotlib. lines.


1 Answers

JupyterLab 3.0+

  1. Install jupyterlab and ipympl.

    For pip users:

    pip install --upgrade jupyterlab ipympl 

    For conda users:

    conda update -c conda-forge jupyterlab ipympl 
  2. Restart JupyterLab.

  3. Decorate the cell containing plotting code with the header:

    %matplotlib widget  # plotting code goes here 

JupyterLab 2.0

  1. Install nodejs, e.g. conda install -c conda-forge nodejs.

  2. Install ipympl, e.g. conda install -c conda-forge ipympl.

  3. [Optional, but recommended.] Update JupyterLab, e.g.
    conda update -c conda-forge jupyterlab==2.2.9==py_0.

  4. [Optional, but recommended.] For a local user installation, run:
    export JUPYTERLAB_DIR="$HOME/.local/share/jupyter/lab".

  5. Install extensions:

     jupyter labextension install @jupyter-widgets/jupyterlab-manager  jupyter labextension install jupyter-matplotlib 
  6. Enable widgets: jupyter nbextension enable --py widgetsnbextension.

  7. Restart JupyterLab.

  8. Decorate with %matplotlib widget.

like image 110
Mateen Ulhaq Avatar answered Sep 17 '22 14:09

Mateen Ulhaq