ipywidgets: useful little buggers

So, the matplotlib slider functionality is basically garbage.

Let’s see if ipywidgets and ipython notebooks do better

sudo pip install ipywidgets


ipython notebook


A basic program with sliders. You can go from there.

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from ipywidgets import interactive
from IPython.display import display

def beat_freq(f1=1.0, f2=1.0):
    times = np.linspace(0,3,100)
    signal = np.sin(2*np.pi*f1*times) + np.sin(2*np.pi*f2*times)
    #print(f1, f2, abs(f1-f2))
    #display(Audio(data=signal, rate=rate))

v = interactive(beat_freq, f1=(0.0,1.0), f2=(0.0,1.0))


Leave a Reply

Your email address will not be published. Required fields are marked *