-
Notifications
You must be signed in to change notification settings - Fork 0
/
lissajous.py
70 lines (52 loc) · 1.57 KB
/
lissajous.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.widgets import Slider
from numpy.linalg import slogdet
plt.style.use('seaborn-v0_8-whitegrid')
# definng the range
x = np.linspace(-10, 10, 100)
# the amplitudes of waves
a = 4 # amplitude of first wave
b = 4
# <-----creating the graph------>
fig, ax = plt.subplots()
plt.subplots_adjust(left=0.1, bottom=0.3)
plot, = plt.plot([], [])
#intialising the plot
def init():
theta = np.pi/2
omega = np.pi/4
t = np.linspace(-4, 4)
x = a*np.sin(omega*t)
y = b*np.sin(omega*t+theta)
plot.set_data(x, y)
init()
#graph decorating
plt.axis('equal')
plt.title("Lissajou's Figures")
plt.xlim(-10, 10)
plt.ylim(-10, 10)
# slider to change ratio of frequency
pos1 = plt.axes([0.1, 0.2, 0.7, 0.03])
slider1 = Slider(pos1, 'w1/w2', valmin=1, valmax=8, valinit=1, valstep=1)
# slider to change the phase difference
pos2 = plt.axes([0.1, 0.14, 0.7, 0.03])
slider2 = Slider(pos2, 'phi', valmin=0, valmax=2*np.pi, valinit=np.pi/2)
#slider to change the ratio of amplitudes
pos3 = plt.axes([0.1, 0.09, 0.7, 0.03])
slider3 = Slider(pos3, 'a2/a1', valmin=0, valmax=1, valinit=1)
# creating the lisajoo's figure
def circle(val):
theta = slider2.val
omega = np.pi/4
r = slider1.val
b = a*slider3.val
t = np.linspace(-4, 4, 600)
x = a*np.sin(omega*t)
y = b*np.sin(r*omega*t+theta)
plot.set_data(x, y)
slider2.on_changed(circle)
slider1.on_changed(circle)
slider3.on_changed(circle)
plt.show()
# <-----x--x---x--x--x----->