ESA-VirES / Swarm-VRE

DEPRECATED: Refer to Swarm-DISC/Swarm_notebooks
https://github.com/Swarm-DISC/Swarm_notebooks
MIT License
1 stars 0 forks source link

`%matplotlib notebook` doesn't work in JupyterLab #1

Open smithara opened 5 years ago

smithara commented 5 years ago

e.g.:

import matplotlib.pyplot as plt
%matplotlib notebook
plt.plot([1,2,3],[1,2,3])

gives error: Javascript Error: IPython is not defined

But it works in Classic Notebook view

%matplotlib widget also doesn't work: ModuleNotFoundError: No module named 'ipympl'

I had a quick look around and it looks like it can be fixed by installing ipympl and maybe also the labextension jupyterlab-manager: https://github.com/matplotlib/jupyter-matplotlib

pacesm commented 5 years ago

I did a quick check and installing the ipympl fixes the classic Jupyter notebook. The JupyterLab seems to be mode complicated. See: https://stackoverflow.com/questions/51922480/javascript-error-ipython-is-not-defined-in-jupyterlab

pacesm commented 5 years ago

As I wrote, the installation of ipmpl fixes the problem in the classic Jupyter notebook. And the original code snippet

import matplotlib.pyplot as plt
%matplotlib notebook
plt.plot([1,2,3],[1,2,3])

creates an interactive widget.

This however does not work in the new JupyerLab environment. There you have to use following code (which works also in the classic notebook)

%matplotlib widget
import matplotlib.pyplot as plt
plt.plot([1,2,3],[1,2,3])

Please note that the %matplotlib widget line must be executed before the matplotlib import. If matplotlib has been already loaded, restart the kernel.

Please also note that JupyterLab does not execute embedded JavaScript and thus many interactive extensions working in the classic Jupyter notebook do not work in JupyterLab anymore. This can be solved by using JupyterLab extensions.