Skip to content

Instantly share code, notes, and snippets.

@kervel
Created April 2, 2020 14:44
Show Gist options
  • Save kervel/575a8b0c984c0c979b5d39e01223eadf to your computer and use it in GitHub Desktop.
Save kervel/575a8b0c984c0c979b5d39e01223eadf to your computer and use it in GitHub Desktop.
# set up plot
fig, ax = plt.subplots(figsize=(6, 4))
ax.set_ylim([-4, 4])
ax.grid(True)
# generate x values
x = np.linspace(0, 2 * np.pi, 100)
def my_sine(x, w, amp, phi):
"""
Return a sine for x with angular frequeny w and amplitude amp.
"""
return amp*np.sin(w * (x-phi))
@widgets.interact(w=(0, 10, 1), amp=(0, 4, .1), phi=(0, 2*np.pi+0.01, 0.01))
def update(w = 1.0, amp=1, phi=0):
"""Remove old lines from plot and plot new one"""
[l.remove() for l in ax.lines]
ax.plot(x, my_sine(x, w, amp, phi), color='C0')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment