Created
April 2, 2020 14:44
-
-
Save kervel/575a8b0c984c0c979b5d39e01223eadf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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