Some setting:
%matplotlib notebook import matplotlib.pyplot as plt from IPython.html.widgets import interactive from IPython.display import display import numpy as np
Create your objects:
fig, ax = plt.subplots() ax.set_xlim(0, .25) ax.set_ylim(-2.5, 2.5) ax.set_title('beat frequencies') lnA, = ax.plot([], [], color='r', label='A') lnB, = ax.plot([], [], color='purple', label='B') lnsum, = ax.plot([], [], color='k', label='signal') ax.legend() max_time = 3 rate = 8000 times = np.linspace(0,max_time,rate*max_time) def beat_freq(f1=220.0, f2=224.0): A = np.sin(2*np.pi*f1*times) B = np.sin(2*np.pi*f2*times) sig = A + B lnA.set_data(times, A) lnB.set_data(times, B) lnsum.set_data(times, sig) plt.draw() beat_freq(0, 0)
and interactive (which, I think, should go into its own cell)
interactive(beat_freq, f1=(200.0,300.0), f2=(200.0,300.0))
You can also protrude objects from another cell:
ax.set_xlim(0, .05) ax.set_ylim(-2, 2) plt.draw()
or
lnB.set_color('g') ax.legend() plt.draw()