Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Using ipympl logic inside python shell or ipython?

Aperta
#68 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
28/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
jupyter, python
Ambito
backend, testing

Direzione di ricerca

Inizia con l’esempio MyVis e riproduci il TraitError in IPython, quindi confrontalo con la configurazione del notebook che usa la magic %matplotlib widget. Verifica come viene selezionato il canvas di matplotlib e determina quale configurazione di test permetterebbe ai casi pytest di usare un canvas widget compatibile al di fuori di Jupyter; il lavoro è completato quando la classe può essere istanziata e testata senza l’errore del canvas Tk.

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

Descrizione

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:

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 <matplotlib.backends.backend_tkagg.FigureCanvasTkAgg object at 0x7f0c48d731d0> <class 'matplotlib.backends.backend_tkagg.FigureCanvasTkAgg'> 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?

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

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.

Altre issue di matplotlib/ipympl

Tutte le issue di matplotlib/ipympl

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.