matplotlib / matplotlib/ipympl

Matplotlib figures are not redrawn in the cell in which they are created

Offen
#258 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

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

## Describe the issue

Using an interactive figure's `canvas.draw()` method does not update the figure if it was created in the same cell as the draw call.

Figure created in the same cell:
![Same cell](https://user-images.githubusercontent.com/1909532/90080052-d39ae300-dcc6-11ea-90cb-1bf3429548c6.gif)

Figure created in another cell:
![different cell](https://user-images.githubusercontent.com/1909532/90080105-02b15480-dcc7-11ea-965d-14114cb27c96.gif)

## Reproduce

1. Open a new notebook in JupyterLab or Notebook
2. Insert the following code:
````
import matplotlib.pyplot as plt
import time

%matplotlib widget

fig = plt.figure()

for i in range(5):
x = list(range(i+2))
xx = [x**2 for x in x]
plt.clf()
plt.plot(x, xx)
fig.canvas.draw()

time.sleep(1)
````
3. Run the cell and observe that the plot does not show until the loop has exited.

Optional:
1. Move the for loop to a separate cell from the figure creation
2. Run cell and observe plot updates during the loop

This can be reproduced using the [scipy notebook docker stack](https://jupyter-docker-stacks.readthedocs.io/en/latest/using/selecting.html#jupyter-scipy-notebook).

## Versions

```
3.8.5 | packaged by conda-forge | (default, Jul 31 2020, 02:39:48)
[GCC 7.5.0]
ipympl version: 0.5.7
jupyter core : 4.6.3
jupyter-notebook : 6.0.3
qtconsole : not installed
ipython : 7.17.0
ipykernel : 5.3.4
jupyter client : 6.1.6
jupyter lab : 2.1.5
nbconvert : 5.6.1
ipywidgets : 7.5.1
nbformat : 5.0.7
traitlets : 4.3.3
Known nbextensions:
config dir: /opt/conda/etc/jupyter/nbconfig
notebook section
jupyter-matplotlib/extension enabled
- Validating: OK
jupyter-js-widgets/extension enabled
- Validating: OK
JupyterLab v2.1.5
Known labextensions:
app dir: /opt/conda/share/jupyter/lab
@bokeh/jupyter_bokeh v2.0.3 enabled OK
@jupyter-widgets/jupyterlab-manager v2.0.0 enabled OK
jupyter-matplotlib v0.7.3 enabled OK
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die bereitgestellte Reproduktion in derselben Zelle in JupyterLab oder Notebook mit dem `%matplotlib widget`-Backend auszuführen, und vergleiche sie dann mit der Version in separaten Zellen. Als erledigt gilt es, wenn `fig.canvas.draw()` die Abbildung während jeder Schleifeniteration sichtbar aktualisiert, statt erst nach Ende der Schleife.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
jupyter-notebook, matplotlib, python
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.