In [1]:
import matplotlib.pylab as plt
import numpy as np
# %matplotlib widget
In [2]:
def get_wave(A, f, theta, phi):
x = theta
y = A*np.sin(2*np.pi*f*theta - phi)
# plt.plot(x, y, alpha)
return x, y
In [3]:
def plot_wave(time, data):
A = data[0]
f = data[1]
phi = data[2]
x, y = get_wave(A, f, time, phi)
plt.figure(figsize = (13, 6))
ax = plt.gca()
plt.plot(x, y, color = 'blue')
ax.set_xlabel('Time', fontsize = 20, color = 'red')
ax.tick_params(axis='x', colors='red')
ax.tick_params(axis='y', colors='red')
In [4]:
steps = 1000
theta = np.linspace(0, 2*np.pi, steps)
data = [2, 3, 0]
plot_wave(theta, data)
In [5]:
def plot_multiple_waves(time, data):
no_of_plots = len(data)
fig, axes = plt.subplots(no_of_plots, figsize = (16, 9))
for i in range(no_of_plots):
ax = axes[i]
w_data = data[i]
A = w_data[0]
f = w_data[1]
phi = w_data[2]
x, y = get_wave(A, f, time, phi)
ax.plot(x, y, color = 'blue', alpha = 1)
ax.set_ylabel(f'Wave {i + 1}', color = 'blue', fontsize = 15)
fig.suptitle('Time', fontsize = 20, color = 'red')
ax.tick_params(axis='x', colors='red')
ax.tick_params(axis='y', colors='red')
ax.set_ylim(-15, 15)
In [6]:
data = [
[6, 1, 0],
[5, 2, 0],
[10, 6, -np.pi/3],
]
steps = 1000
theta = np.linspace(0, 2*np.pi, steps)
# time = theta
plot_multiple_waves(theta, data)
In [7]:
def plot_a_fourier_waves(data, time):
no_of_plots = len(data)
# fig, axes = plt.subplots(no_of_plots, figsize = (16, 9))
# xs = np.zeros(len(time))
ys = np.zeros(len(time))
for i in range(no_of_plots):
# ax = axes[i]
w_data = data[i]
A = w_data[0]
f = w_data[1]
phi = w_data[2]
x, y = get_wave(A, f, time, phi)
ys += y
fig = plt.figure(figsize = (16, 3))
ax = plt.gca()
plt.plot(x, ys, color = 'blue', alpha = 1)
# ax.set_ylabel(f'Wave {i + 1}', color = 'blue', fontsize = 15)
fig.suptitle('Time', fontsize = 20, color = 'red')
ax.tick_params(axis='x', colors='red')
ax.tick_params(axis='y', colors='red')
lim = max(np.abs(ys))
ax.set_ylim(-(lim+3), lim+3)
In [8]:
data = [
[6, 1, 0],
[5, 2, 0],
[10, 6, -np.pi/3],
]
steps = 1000
theta = np.linspace(0, 2*np.pi, steps)
# time = theta
plot_a_fourier_waves(data, theta)
In [40]:
def plot_multiple_waves_fourier_wave(data, time, alpha = 1):
no_of_plots = len(data) + 2
fig, axes = plt.subplots(no_of_plots, figsize = (16, 9))
xs = np.zeros(len(time))
ys = np.zeros(len(time))
for i in range(no_of_plots):
ax = axes[i]
if i < no_of_plots - 2:
w_data = data[i]
A = w_data[0]
f = w_data[1]
phi = w_data[2]
x, y = get_wave(A, f, time, phi)
ax.plot(x, y, color = 'blue', alpha = alpha)
xs += x
ys += y
elif i == no_of_plots - 2:
for j in range(no_of_plots-2):
w1_data = data[j]
A = w1_data[0]
f = w1_data[1]
phi = w1_data[2]
x1, y1 = get_wave(A, f, time, phi)
ax.plot(x1, y1, color = 'green', alpha = alpha)
else:
ax.plot(xs, ys, color = 'red', alpha = alpha)
fig.suptitle('Time', fontsize = 20, color = 'red')
ax.tick_params(axis='x', colors='red')
ax.tick_params(axis='y', colors='red')
ax.set_xlim(min(time), max(time))
ax.set_ylim(-20, 20)
In [43]:
data = [
[6, 1, 0],
[5, 2, 0],
[10, 6, -np.pi/3],
[1, 1, 0],
]
steps = 1000
theta = np.linspace(0, 2*np.pi, steps)
# time = theta
plot_multiple_waves_fourier_wave(data, theta)
In [42]:
def get_circle(A, f, theta, phi):
x = A*np.cos(2*np.pi*f*theta - phi)
y = A*np.sin(2*np.pi*f*theta - phi)
# ax.plot(x, y, color = color, alpha = alpha)
return x, y
In [12]:
def plot_circles_fourier(data, time, alpha = 1):
x = 0
y = 0
for A, f, phi in data:
x_temp, y_temp = get_circle(A, f, time, phi)
x += x_temp
y += y_temp
fig = plt.figure(figsize = (6, 6))
ax = plt.gca()
plt.plot(x, y, alpha, color = 'blue')
ax.tick_params(axis='x', colors='red')
ax.tick_params(axis='y', colors='red')
In [13]:
data = [
[8, 1, 0],
[5, 2, 0],
# [50, 6, -np.pi/3],
]
steps = 1000
theta = np.linspace(0, 2*np.pi, steps)
plot_circles_fourier(data, theta)
plt.gca().set_aspect('equal')
In [14]:
def plot_circular_wave(data, time):
A = data[0]
f = data[1]
phi = data[2]
x, y = get_circle(A, f, time, phi)
plt.figure(figsize = (13, 6))
ax = plt.gca()
plt.plot(x, y, color = 'blue')
ax.set_xlabel('Time', fontsize = 20, color = 'red')
ax.tick_params(axis='x', colors='red')
ax.tick_params(axis='y', colors='red')
ax.set_aspect('equal')
In [15]:
data = [2, 3, 0]
steps = 1000
theta = np.linspace(0, 2*np.pi, steps)
plot_circular_wave(data, theta)
In [ ]:
In [16]:
def plot_circles_fourier(data, time, alpha = 1):
no_of_plots = len(data) + 2
fig, axes = plt.subplots(ncols = no_of_plots, figsize = (16, 9))
xs = np.zeros(len(time))
ys = np.zeros(len(time))
for i in range(no_of_plots):
ax = axes[i]
if i < no_of_plots - 2:
w_data = data[i]
A = w_data[0]
f = w_data[1]
phi = w_data[2]
x, y = get_circle(A, f, time, phi)
ax.plot(x, y, color = 'blue', alpha = alpha)
xs += x
ys += y
elif i == no_of_plots - 2:
for j in range(no_of_plots-2):
w1_data = data[j]
A = w1_data[0]
f = w1_data[1]
phi = w1_data[2]
x1, y1 = get_circle(A, f, time, phi)
ax.plot(x1, y1, color = 'green', alpha = alpha)
else:
ax.plot(xs, ys, color = 'red', alpha = alpha)
ax.set_xlim(-12, 12)
ax.set_ylim(-12, 12)
ax.set_aspect('equal')
In [17]:
data = [
[6, 4, 0],
[2, 9, 0],
# [50, 6, -np.pi/3],
]
plot_circles_fourier(data, theta)
In [18]:
def plot_multiple_circular_waves(data, time):
no_of_plots = len(data)
fig, axes = plt.subplots(ncols = no_of_plots, figsize = (16, 9))
for i in range(no_of_plots):
ax = axes[i]
w_data = data[i]
A = w_data[0]
f = w_data[1]
phi = w_data[2]
x, y = get_circle(A, f, time, phi)
ax.plot(x, y, color = 'blue')
ax.set_xlim(-12, 12)
ax.set_ylim(-12, 12)
ax.set_aspect('equal')
ax.set_title(f'Wave {i + 1}', fontsize = 20, color = 'red')
ax.tick_params(axis='x', colors='red')
ax.tick_params(axis='y', colors='red')
In [ ]:
In [19]:
data = [
[8, 1, 0],
[5, 2, 0],
# [50, 6, -np.pi/3],
]
steps = 1000
theta = np.linspace(0, 2*np.pi, steps)
plot_multiple_circular_waves(data, theta)
In [ ]:
In [ ]: