Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ipympl logic inside python shell or ipython? #68

Open
codingS3b opened this issue Oct 10, 2018 · 0 comments
Open

Using ipympl logic inside python shell or ipython? #68

codingS3b opened this issue Oct 10, 2018 · 0 comments

Comments

@codingS3b
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant