Interactive matplotlib in jupyterlab no longer working

Hi all,

I have updated a number of packages (the whole jupyter/jupyterlab/matplotlib stack) and now I’m not able to get interactive plots with matplotlib in JupyterLab. Previously, I have used the magic %matplotlib notebook to activate this interactive plot mode. Now, the notebook shows an error Javascript Error: IPython is not defined.

Below is the environment.yml file I am currently using where this fails as well as one where it works. I am installing via mamba using the conda-forge channel on linux.

Many thanks in advance!


name: wm01-rabbit
  - conda-forge
  - bioconda
  - python=3.11
  - pip=23.1.2
  - snakemake-minimal=7.26.0

  - numpy=1.24.3
  - pandas=2.0.2

  - matplotlib=3.7.1
  - seaborn=0.12.2

  - scipy=1.10.1
  - scikit-image=0.20.0
  - scikit-learn=1.2.2

  - pytables=3.8.0

  - imageio=2.28.1
  - imageio-ffmpeg=0.4.8

  - pymc=5.3.0
  - python-graphviz=0.20.1

  - nbgrader=0.8.2
  - jupyterhub=4.0.1
  - nbdev=2.2.10
  - nbconvert=7.4.0
  - jupyter_server=1.23.4

  - requests=2.31.0

  - biopython=1.81
  - scanpy=1.9.3

  - pip:
      - adskalman==0.3.11
      - dabest==2023.2.14
      - figurefirst==0.0.6

And this was working:

name: pm21-tiger
  - conda-forge
  - bioconda
  - python=3.10.4
  - snakemake=7.8.2
  - nbgrader=0.8.1
  - sqlalchemy=1.4.37
  - jinja2=3.1.2
  - nbconvert=6.5.0
  - jupyterhub=2.3.1
  - jupyter_server=1.17.1
  - numpy=1.22.4
  - matplotlib=3.5.1
  - pandas=1.4.2
  - scipy=1.8.1
  - seaborn=0.11.2
  - imageio=2.9.0
  - imageio-ffmpeg=0.4.7
  - scikit-image=0.19.2
  - scikit-learn=1.1.1
  - python-graphviz=0.20
  - nose=1.3.7
  - pip=22.1.2
  - biopython=1.79
  - requests=2.28.0
  - pyyaml=6.0
  - sympy=1.10.1
  - pytables=3.7.0
  - panel=0.13.0
  - hvplot=0.7.3
  - napari=0.4.12
  - pymc=4.2.2
  - filterpy=1.4.5
  - pip:
      - adskalman==0.3.11
      - dabest==0.3.1
      - figurefirst==0.0.6

Where is ipympl?
With that it is %matplotlib widget or %matplotlib ipympl, see here and here.

I noticed the same recently, and so I made a small experiment to summarize what was working where, and here it is

of course you need to pip install ipympl to use either widget or ipympl

for that reason I’m going to switch to using
%matplotlib ipympl
because it also works in the context of vs-code, and it’s often handy to be able to use vs-code as well…

frontend %matplotlib works ?
nb6 notebook YES
widget YES
ipympl YES
nb7 notebook KO - IPython is not defined
widget YES
ipympl YES
jlab4 notebook KO - IPython is not defined
widget YES
ipympl YES
vscode notebook KO
widget KO
ipympl YES
1 Like