我創建一個Python模擬,在引力波車型的水顆粒。到目前爲止我的代碼是Python的模擬工作不
import numpy as np
#import matplotlib
import matplotlib.pyplot as plt
#import pylab
#pylab.ion()
h = 2 # water depth
D = 0.4 # wave amplitude
k = 1 # wave number
ds = 0.5
x = np.arange(0, 15+ds, ds)
y = np.arange(0, h+ds, ds)
g = 10
w = np.sqrt(g*k*np.tanh(k*h))
T = 2*np.pi/w
xx,yy = np.meshgrid(x,y)
hp = plt.plot(xx[:],yy[:],'x')
plt.axis('equal')
plt.axis([0,15,0,8]) #axis equal
N = 24
#matplotlib.interactive(True)
t = 0
while (True):
t = t + T/N
dispx = D/np.sinh(k*h) * np.outer(np.cosh(k*y), np.cos(k*x-w*t))
dispy = D/np.sinh(k*h) * np.outer(np.sinh(k*y), np.sin(k*x-w*t))
plt.setp(hp,'XData',xx[:]+dispx[:], 'YData',yy[:]+dispy[:])
plt.drawNow()
我只是得到一個靜態圖像,我知道我很近。我應該添加什麼來讓所有的東西都移動?最好是實時繪圖。
Matplotlib具有['animation'包(http://matplotlib.org/api/animation_api.html)和[一些例子](http://matplotlib.org/1.3.1/examples/animation/index .html)如何使用它。我強烈希望他們在哈克動畫,有的在我的實驗室儘量讓所有的'pylab' /'ion'廢話,也許它會爲你工作爲好。它使出口視頻非常容易。 –
有沒有一種快速的方式來讓現有的代碼工作?我正在翻譯來自Matlab的一些代碼,我還不是Python專家。 –