matplotlib / matplotlib/ipympl

Displaying a previously created Matplotlib figure in a widget

Offen
#203 8 Kommentare 0 Reaktionen 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

I'm trying to find a way to take a figure previously created, and show it inside a widget, _without losing interactivity._
Here's a short version of my approach (which may not be the right one):

```python
fig = plt.figure() # previously created figure
out = widgets.Output()
with out:
display(fig)
# other things happening
display(widgets.HBox([fig.canvas, some_other_fig]))
```

If I first create a figure in the notebook outside of an `Output` widget, and then wish to include it later inside something like an `HBox` next to a second figure, I seem to lose interactivity with the figure (including the nice ipympl zoom interface).

Here is a [nbviewer view](https://nbviewer.jupyter.org/github/thomasaarholt/tests/blob/master/Output%20Example%20Notebook.ipynb) of a MWE notebook I created, download it top right on the window. It's best if one downloads it and runs it since the first figure appears buggy in the nbviewer.

Additionally, and I might create a new issue for this - if I call `fig1` at the end of the notebook, I get an unexpected error. Here I'd expect the regular figure to be shown. The error is `AttributeError: 'NoneType' object has no attribute '_send_event'`.

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

Lade das verlinkte Output Example Notebook herunter und führe es aus, um das Verhalten mit der zuvor erstellten Abbildung, dem Output widget und HBox zu reproduzieren. Beginne damit nachzuverfolgen, wie die angezeigte Abbildung und ihr Canvas behandelt werden, und überprüfe dann, dass die Abbildung ihre ipympl-Interaktivität in HBox beibehält und dass das Anzeigen von fig1 nicht mehr den gemeldeten NoneType-Fehler auslöst.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
jupyter-notebook, matplotlib, python
Bereich
data-visualization, frontend
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.