-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwave.py
49 lines (35 loc) · 856 Bytes
/
wave.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
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
wavelength=2
#波长
T=20
#周期
def f(x,y):
#单波
return np.e**((2*np.pi/wavelength)*np.sqrt(y**2+(x)**2)* 1j)
x= np.linspace(-5,5, 200)
y= np.linspace(-5,5, 200)
def g(i): #时间因子
return np.e**((-2*np.pi/T)*i*1j)
fig=plt.figure()
ax=Axes3D(fig)
ax.set_xlim(-5,5)
ax.set_ylim(-5,5)
ax.set_zlim(-5,5)
X, Y = np.meshgrid(x, y)
t=0
F=(g(t)*f(X,Y)).real
#ax.contour(X,Y,Z) #等高线图
line=ax.plot_surface(X,Y,F)
def animate(t):
F=(g(t)*f(X,Y)).real
plt.cla()
ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)
ax.set_zlim(-5, 5)
line=ax.plot_surface(X,Y,F)
return line
ani=FuncAnimation(fig=fig,func=animate,frames=300,interval=0.1,blit=False)
plt.show()