logo

... ipywidgets: interact



Notes

To create a simple function with a slider attached, you can run;

from ipywidgets import interact

import numpy as np
import matplotlib.pylab as plt

@interact(p=(0.001, 0.2, 0.01))
def f(p):
    n = np.linspace(1, 100, 100)
    plt.plot(n, n*0.02*(1-0.02)**n, label="p=0.02");
    plt.plot(n, n*p*(1-p)**n, label=f"p={np.round(p, 3)}");
    plt.legend()

Feedback? See an issue? Something unclear? Feel free to mention it here.



If you want to be kept up to date, consider signing up for the newsletter.