matplotlib / matplotlib/ipympl
Automatically started kernels in jupyterlab break matplotlib
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Jupyter Notebook
- Sterne
- 1.7k
- Forks
- 234
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das Problem mit der aufgeführten conda-Umgebung, jupyter lab und dem Beispiel %matplotlib widget zu reproduzieren. Vergleiche den Kernelzustand nach dem erneuten Öffnen des Notebooks mit dem Zustand nach der Verwendung von Kernel > Shut Down Kernel und Kernel > Restart Kernel; als erledigt gilt die Aufgabe, wenn das erneut geöffnete Notebook das Diagramm ohne schwarze Ausgabe oder No such comm-Warnungen rendert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- jupyter-notebook, matplotlib, numpy
- Bereich
- backend, frontend
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100