【发布时间】: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