Reputation: 141
I have been copy pasting code snippets from http://goo.gl/J802b0 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)
Upvotes: 6
Views: 1658
Reputation: 87376
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).
Upvotes: 4