matplotlib / matplotlib/ipympl

Closing a figure from the notebook does not close the python figure

Aperta
#4 15 commenti 8 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Jupyter Notebook
Stelle
1.7k
Fork
234
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

This is essentially a regression of https://github.com/matplotlib/matplotlib/issues/4841 which happened when the nbagg backend was converted to a widget.

To reproduce create a cell with a simple plot.

```
plt.plot(range(10))
plt.show()
```

re execute the cell and observe that the figure count goes up and memory consumption goes up too. If you continue doing this you will eventually have more than 20 open figures and matplotlib will print a warning even if you only have one figure displayed.

The same is true if you explicitly close the widget using the widget close cross on the left of the figure.

I have spent some time trying to figure out how to best fix this but don't really know how to best do this. [This function](https://github.com/matplotlib/jupyter-matplotlib/blob/master/js/src/mpl_widget.js#L122)
is meant to trigger a close message to the python side when the figure is removed from the DOM but no longer works.

The old no longer existing [close button](https://github.com/matplotlib/jupyter-matplotlib/blob/master/js/src/mpl_widget.js#L115) is also intended to send a close signal to the python layer but this is not hooked up to the widget close button.

https://github.com/matplotlib/matplotlib/issues/6414 has some more related issues.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da js/src/mpl_widget.js, in particolare dalla funzione di rimozione dal DOM e dalla gestione del pulsante di chiusura del widget descritte nell’issue. Riproduci il problema eseguendo ripetutamente la cella del grafico e chiudendo esplicitamente il widget, quindi verifica che il numero di figure, l’uso della memoria e l’avviso relativo a più di 20 figure non aumentino più.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, jupyter-notebook, python
Ambito
backend, frontend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.