The weight for each sine wave, w1 and w2 respectivelly can be changed.
import numpy as np
from matplotlib import pyplot as plt
from ipywidgets import interact
from ipywidgets import interactive, fixed
%matplotlib inline
fs = 100 #Hz
t = np.arange(0,200) / fs # time 1D
x1 = np.sin(2*np.pi*3*t) # 3 Hz sine wave
x2 = np.sin(2*np.pi*7*t) # 7 Hz sine wave
x = x1 + x2 # adding both sine waves
def add_sines(x1, w1=1, w2=1):
plt.figure(2)
x = w1*x1 + w2*x2
plt.plot(t, x)
plt.ylim(-2.2, 2.2)
plt.xlabel('time (s)')
plt.ylabel('amplitude')
plt.title(str(w1)+ '$\cdot$sin(2$\pi\cdot$3$\cdot$t) + ' + str(w2) + '$\cdot$sin(2$\pi\cdot$7$\cdot$t)');
plt.show()
interactive_plot = interactive(add_sines, w1=(0, 1, 0.1), w2=(0, 1, 0.1),
x1=fixed(x1), x2=fixed(x2), t=fixed(t))
output = interactive_plot.children[-1]
output.layout.height = '350px'
interactive_plot