【发布时间】:2022-01-23 19:29:01
【问题描述】:
我有一个形状为(50,3) 的数组x_trj,我想使用该数组的第一列和第二列(分别为x 和y 坐标)绘制二维轨迹。这个轨迹将在一个圆圈的顶部。到目前为止,这是我的代码:
from matplotlib.animation import FuncAnimation
import matplotlib.pyplot as plt
fig = plt.figure()
ax = plt.axes(xlim=(-5, 5), ylim=(-5, 5))
line, = ax.plot([], [], lw=2)
# Plot circle
theta = np.linspace(0, 2*np.pi, 100)
plt.plot(r*np.cos(theta), r*np.sin(theta), linewidth=5)
ax = plt.gca()
def animate(n):
# Plot resulting trajecotry of car
for n in range(x_trj.shape[0]):
line.set_xdata(x_trj[n,0])
line.set_ydata(x_trj[n,1])
return line,
anim = FuncAnimation(fig, animate,frames=200, interval=20)
但是,动画结果是一个静止的人物。我在文档页面上查看了 Matplotlib 动画示例,但我仍然无法弄清楚我的 animate(n) 函数在这种情况下应该是什么样子。有人可以给我一些提示吗?
【问题讨论】:
-
我刚试过,但动画结果是一个静止的人物
标签: python matplotlib