6

I have been copy pasting code snippets from https://nbviewer.org/github/jakevdp/matplotlib_pydata2013/blob/master/notebooks/03_Widgets.ipynb into an ipython notebook console to try out these matplotlib features. I get the sliders and buttons appearing after I shift-enter the code cells, but without any functionality.

I am running ipython notebook --pylab inline.

Any suggestions would be very much appreciated.

Here is an example that plots a sine wave and adds next and previous buttons that supposedly will change the axes, but I get no interactivity:

from matplotlib.widgets import Button

fig, ax = plt.subplots()
fig.subplots_adjust(bottom=0.2)

t = np.linspace(0, 10, 1000)
line, = plt.plot(t, np.sin(t), lw=2)

class Index:
    dt = 0
    def next(self, event):
        self.dt -= 1
        line.set_ydata(np.sin(t + self.dt))
        fig.canvas.draw()

    def prev(self, event):
        self.dt += 1
        line.set_ydata(np.sin(t + self.dt))
        fig.canvas.draw()

callback = Index()
axprev = plt.axes([0.7, 0.05, 0.1, 0.075])
axnext = plt.axes([0.81, 0.05, 0.1, 0.075])

bnext = Button(axnext, '>')
bnext.on_clicked(callback.next)

bprev = Button(axprev, '<')
bprev.on_clicked(callback.prev)
0

1 Answer 1

4

The figures are served in the web-browser as a png and do not have kind of image map (look at the source of what the note book serves to you) so I don't think this functionality exists in in-line figures yet.

The code should work if you use one of included interactive backends (with your gui toolkit of choice).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.