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.
Jupyter Notebook has support for many kinds of interactive outputs, including the ipywidgets ecosystem as well as many interactive visualization libraries.
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.
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.
Install jupyterlab
and ipympl
.
For pip
users:
pip install --upgrade jupyterlab ipympl
For conda
users:
conda update -c conda-forge jupyterlab ipympl
Restart JupyterLab.
Decorate the cell containing plotting code with the header:
%matplotlib widget # plotting code goes here
Install nodejs
, e.g. conda install -c conda-forge nodejs
.
Install ipympl
, e.g. conda install -c conda-forge ipympl
.
[Optional, but recommended.] Update JupyterLab, e.g.conda update -c conda-forge jupyterlab==2.2.9==py_0
.
[Optional, but recommended.] For a local user installation, run:export JUPYTERLAB_DIR="$HOME/.local/share/jupyter/lab"
.
Install extensions:
jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter labextension install jupyter-matplotlib
Enable widgets: jupyter nbextension enable --py widgetsnbextension
.
Restart JupyterLab.
Decorate with %matplotlib widget
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With