【问题标题】:How to make an animation of a Lissajous curve如何制作利萨如曲线的动画
【发布时间】:2019-04-15 09:23:44
【问题描述】:

我想用参数化来制作曲线的动画(你逐渐绘制它的地方):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' object is not iterable 出现了......我该如何解决它?

谢谢

【问题讨论】:

  • 请注意,由于 numpy 的广播和矢量化,你可以只写 x=np.sin(3*t)y=np.sin(4*t) 完全避免使用循环。

标签: python matplotlib animation


【解决方案1】:

您正在尝试迭代一个整数 (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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-07
    • 1970-01-01
    • 2021-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-04
    相关资源
    最近更新 更多