[IPython-dev] IPython notebook widgets for interactive matplotlib figures

Antonino Ingargiola tritemio at gmail.com
Tue Jul 29 14:36:49 EDT 2014


HI to all,

I'm following up to this SO question:

http://stackoverflow.com/questions/24961674/ipython-notebook-widgets-for-matplotlib-interactivity

To summarize the problem is that I want to "modify" a plot via some
notebook widgets, for example adding a cursor (however can can think about
any plot tweak including adding/removing data).

Putting the following code in a single cell:

fig, ax = plt.subplots()
ax.plot([3,1,2,4,0,5,3,2,0,2,4])

vline = ax.axvline(1)
hline = ax.axhline(0.5)
def set_cursor(x, y):
    vline.set_xdata((x, x))
    hline.set_ydata((y, y))
    display(fig)

interact(set_cursor, x=(1, 9, 0.01), y=(0, 5, 0.01))


results in 2 figures being displayed: one by the standard notebook
machinery in the Out field and one by the interact call in the widgets
space (between the code cell and the output). Moving the slider makes the
first plot to disappear.

Is this the expected behavior? Am I doing something wrong? Is there a way I
can inhibit the first figure display?

Thanks,
Antonio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140729/8a3ab622/attachment.html>


More information about the IPython-dev mailing list