matplotlib / matplotlib/ipympl
Automatically started kernels in jupyterlab break matplotlib
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 1.7k
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
When a jupyterlab server is shut down, it remembers which files were open the next time it starts. When the jupyterlab server is restarted, it opens those files and starts a kernel for each one. These kernels are cursed. If %matplotlib widget is used in any of these open files, matplotlib will show a black image instead of the expected plot. Errors like [IPKernelApp] WARNING | No such comm: fcef8c0be3a345e493e771adbbb0df16 appear in the server's standard out. Restarting the kernel does not help. The kernel must be shut down and then restarted. Only then will the notebook display plots correctly.
How to reproduce
- Create a new conda environment with jupyterlab and matplotlib installed and start the server.
conda create -n temp -c conda-forge jupyterlab==1.0.9 matplotlib==3.1.1 ipympl==0.3.3
conda activate temp
jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter lab
-
Create a new notebook in JupyterLab and leave it open.
-
Shutdown the server and restart it. Note that the new file has a running kernel.
-
Put some plotting code using
%matplotlib widgetin the notebook and run it. A black box will appear instead of a plot. Error messages will stream in the console.
%matplotlib widget
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 1, 500)
y = np.sin(4 * np.pi * x) * np.exp(-5 * x)
fig, ax = plt.subplots()
ax.fill(x, y, zorder=10)
ax.grid(True, zorder=5)
plt.show()
- Navigate to Kernel > Shut Down Kernel and then Kernel > Restart Kernel. Run the notebook again and the plots will appear.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the listed conda environment, jupyter lab, and the %matplotlib widget example. Compare the kernel state after reopening the notebook with the state after using Kernel > Shut Down Kernel and Kernel > Restart Kernel; done means the reopened notebook renders the plot without black output or No such comm warnings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, matplotlib, numpy
- Domain
- backend, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100