In [ ]:
import numpy as np
import matplotlib.pyplot as plt

from ipywidgets import interact, interactive, fixed

Welcome!

This notebook demos an interactive cell within a slideshow using RISE


In [ ]:
# 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()

Executing a static function call

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.


In [ ]:
# Here's a static evaluation with default args
plot_graph(1.2,0.121,2.5)

Interactive widgets

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.


In [ ]:
interact(plot_graph, a=(-2,2,0.2), b=(-2,3,0.1), c=(-2,2,0.1));

In [ ]: