Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

%matplotlib notebook doesn't work in JupyterLab #1

Open
smithara opened this issue Jul 1, 2019 · 2 comments
Open

%matplotlib notebook doesn't work in JupyterLab #1

smithara opened this issue Jul 1, 2019 · 2 comments

Comments

@smithara
Copy link
Member

smithara commented Jul 1, 2019

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
Copy link
Collaborator

pacesm commented Jul 1, 2019

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
Copy link
Collaborator

pacesm commented Jul 2, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants