簡體   English   中英

如何制作李沙育曲線的動畫

[英]How to make an animation of a Lissajous curve

我想用參數化制作曲線的動畫(在其中遞增繪制):x(t)= sin(3t)和y(y)= sin(4t),其中t [0,2pi]。

嘗試:

%matplotlib notebook

import matplotlib.pyplot as plt
import math
import numpy as np

# set the minimum potential
rm = math.pow(2, 1 / 6)
t = np.linspace(-10, 10, 1000, endpoint = False)
x = []
y = []

for i in len(t): #TypeError 'int' object is not iterable
    x_i = np.sin( 3 * t[i] )
    y_i = np.sin( 4 * t[i] )
    x.append(x_i)
    y.append(y_i)

# plot the graph
plt.plot(x,y)

# set the title
plt.title('Plot sin(4t) Vs sin(3t)')

# set the labels of the graph
plt.xlabel('sin(3t)')
plt.ylabel('sin(4t)')

# display the graph
plt.show()

但是TypeError'int'對象不是可迭代的...我該如何解決?

謝謝

您正在嘗試遍歷整數( i in len(t)

相反,您需要遍歷數組:

for i in t:
    x_i = np.sin( 3 * i )
    y_i = np.sin( 4 * i )
    x.append(x_i)
    y.append(y_i)

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM