matplotlib / matplotlib/ipympl

Using ipympl logic inside python shell or ipython?

Offen
#68 0 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 have a class that inherits from the `ipywidgets.widgets.VBox` and adds a `figure.canvas` instance of a matplotlib figure to its children like so:

```python
import matplotlib.pyplot as plt
from ipywidgets import widgets

plt.ioff()

class MyVis(widgets.VBox):
def __init__(self):
super().__init__()
self.fig = plt.figure()
self.children = [self.fig.canvas]

m = MyVis()
```

This works fine when I use this class within jupyter notebooks using the `%matplotlib widget` magic before executing the above code.
When executed within ipython I get
`TraitError: Element of the 'children' trait of a MyVis instance must be a Widget, but a value of was specified.`
since of course `ipympl` and its magic are not active.

Since I also want to have unit-tests for this class (and others that make use of this class) using `pytest`, it would be nice to get around this problem.
Can I enable the `ipympl` way of handling figures somehow in the python shell (similar to using the `%matplotlib widget` magic in the notebook) that would allow my tests to run?

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 mit dem MyVis-Beispiel und reproduziere den TraitError in IPython. Vergleiche ihn anschließend mit dem Notebook-Setup unter Verwendung des `%matplotlib widget`-Magics. Prüfe, wie die matplotlib-Canvas ausgewählt wird, und ermittle, welches Test-Setup es den pytest-Testfällen ermöglichen würde, außerhalb von Jupyter eine kompatible Widget-Canvas zu verwenden; als erledigt gilt die Aufgabe, wenn die Klasse instanziiert und getestet werden kann, ohne dass der Tk-Canvas-Fehler auftritt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
jupyter, python
Bereich
backend, testing
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
28/100

Neue Issues direkt in Ihr Postfach

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