import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import interact, interactive, fixed
This notebook demos an interactive cell within a slideshow using RISE
# Let's define a function (this cell can be hidden from the slideshow if you like)
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import interact
def plot_graph(a=-0.1,b=0.8,c=-0.3):
# some arbitrary function of a,b,c
x = np.linspace(0,10,100)
y = a*a*np.square(x) + (b+a)*np.sin(x) + (c-a)*np.cos(x) + c*x
plt.plot(x,y)
plt.ylim(-30,30)
plt.show()
Change the numbers in the function call, hit ctrl-enter and it will re-execute. Everything shifts down when you change a number and re-execute, then shifts back to the 'correct' position if you execute another time without changing anything.
# Here's a static evaluation with default args
plot_graph(1.2,0.121,2.5)
Now you can wiggle the sliders and see the effect on the graph. Yay! But if you re-execute the cell with ctrl-enter, the position will be broken. If you go back a slide and re-launch this slide, the position is correct again.
interact(plot_graph, a=(-2,2,0.2), b=(-2,3,0.1), c=(-2,2,0.1));