matplotlib / matplotlib/ipympl
Using ipympl logic inside python shell or ipython?
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
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 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