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

MWE for plot widget #50

Closed
ebatz opened this issue Jun 11, 2018 · 2 comments
Closed

MWE for plot widget #50

ebatz opened this issue Jun 11, 2018 · 2 comments

Comments

@ebatz
Copy link

ebatz commented Jun 11, 2018

The following code used to work in previous versions,

import ipympl
import matplotlib.pyplot as plt

import ipywidgets as widgets
from IPython.display import display

aFig = plt.figure()
aBox = widgets.Box(children=[aFig.canvas,])

display(aBox)

and the figure content could then be updated later by plotting onto its axes and subsequently calling canvas's draw(). After upgrading to the current version this snippet fails with

TraitError: Element of the 'children' trait of a Box instance must be a Widget, but a value of <matplotlib.backends.backend_agg.FigureCanvasAgg object at ...> <class 'matplotlib.backends.backend_agg.FigureCanvasAgg'> was specified.

Using the %matplotlib ipympl magic command, there is no such error message, but no plot gets rendered. Based on #39 my understanding was that the only difference between importing ipympl and using the magic command would be when the plot gets shown, but now I cannot seem to get either to work.

What is the preferred way to set up an interactive figure and retain control over its positioning?

@ebatz
Copy link
Author

ebatz commented Jul 5, 2018

Using the %matplotlib widget magic the code snippet does not throw an error, but it also does not produce a plot,

%matplotlib widget

import matplotlib.pyplot as plt
import ipywidgets as widgets

from IPython.display import display

fig = plt.figure()
fig.add_subplot(1,1,1).plot([1,2,3])

fig.canvas.draw()

box = widgets.Box(children=[fig.canvas,])
display(box)

fig.canvas.draw()

What's the missing piece?

@ebatz
Copy link
Author

ebatz commented Jul 10, 2018

Thanks, commits fba1226 and 0b775d1 now demonstrate the use of the canvas as a widget in the example notebook.

The reason that the previous code snippet did not produce a plot remains unclear to me -- maybe similar to #45 -- but it works now after upgrading all the relevant modules.

@ebatz ebatz closed this as completed Jul 10, 2018
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