(Python)无法显示Lissajous曲线图

时间:2015-08-01 00:04:14

标签: python matplotlib

编写了一个程序来绘制Lissajous曲线图,但无论出于什么原因,当图表显示时它都是空白的。我错过了什么吗?

#this program given a set of parameters calculates and graphs Lissajous Curves

from numpy import *
from matplotlib.pyplot import *
from math import *

t=arange(0,4*pi/200)
#first set of parameters
A=1
B=1
a1=1
b1=2
d=pi/2
#second set of parameters
a2=2
b2=3
X1=[]
Y1=[]
Y2=[]
X2=[]
x1=A*sin(a1*t+d)
y1=B*sin(b1*t)
x2=A*sin(a2*t+d)
y2=B*sin(b2*t)
X1=append(X1,x1)
Y1=append(Y1,y1)
X2=append(X2,x2)
Y2=append(Y2,y2)
figure()
plot(t,X1, color='blue')
plot(t,Y1, color='pink')
plot(t,X2, color='purple')
plot(t,Y2, color='green')
show()

细节 细节 细节 细节

2 个答案:

答案 0 :(得分:0)

要使其成为Lissajou,我们必须绘制X与Y而不是t。使用评论引出的提示

#this program given a set of parameters calculates and graphs Lissajous Curves

import numpy as np
from matplotlib.pyplot import figure, plot, show
from math import pi

t=np.arange(0, 4 * pi / 2, 0.001)

#first set of parameters
A = 1
B = 1
a1 = 1
b1 = 2
d = pi/2

#second set of parameters
a2 = 2
b2 = 3

X1 = A * np.sin(a1 * t + d)
Y1 = B * np.sin(b1 * t)

X2 = A * np.sin(a2 * t + d)
Y2 = B * np.sin(b2 * t)

figure()
plot(X1, Y1, color='blue')
plot(X2, Y2, color='pink')
show()

enter image description here

答案 1 :(得分:-1)

试试这个:

from numpy import *
from matplotlib.pyplot import *
from math import *

t=arange(0,4*pi/2,0.0001)
print(t)
#first set of parameters
A=1
B=1
a1=1
b1=2
d=pi/2
#second set of parameters
a2=2
b2=3
X1=[]
Y1=[]
Y2=[]
X2=[]
for i in range(len(t)):
    x1=A*sin(a1*t[i]+d)
    y1=B*sin(b1*t[i])
    x2=A*sin(a2*t[i]+d)
    y2=B*sin(b2*t[i])
    X1=append(X1,x1)
    Y1=append(Y1,y1)
    X2=append(X2,x2)
    Y2=append(Y2,y2)
figure()
plot(t,X1, color='blue')
plot(t,Y1, color='pink')
plot(t,X2, color='purple')
plot(t,Y2, color='green')
show()