【发布时间】:2021-11-01 22:50:56
【问题描述】:
我想使用某些点生成动画曲线。但是,当我使用下面的代码时,没有显示动画,并且图片的 x 坐标和 y 坐标不断变化。我使用FuncAnimation函数,我传递给这个函数的参数是plot_gesture,这个函数绘制了所有的点。
我的轨迹是一个列表,它的元素都是列表(长度为2),就像[[2.5,2], [4,3.5], [2,6]....] 我的位置是一个ndarray,它的元素都是元组(长度为2),就像((3,5),(6,7)......) 轨迹的长度远大于位置的长度,因为位置是轨迹的采样点的所有点。轨迹是整个轨迹的所有点。所以,我需要把轨迹上的所有点都画出来,把位置的点分散一下
def plot_gesture(i = int):
X = []
Y = []
X_point = []
Y_point = []
for x in trajectory[:i]:
X.append(x[0])
Y.append(x[1])
for x in position[:i]:
X_point.append(x[0])
Y_point.append(x[1])
plt.plot(X, Y)
for x, y in zip(X_point, Y_point):
plt.scatter(x, y)
if __name__ == "__main__":
trajectory = point_list
position = np.array(sampled_all_points)
ani=animation.FuncAnimation(fig= fig,func= plot_gesture, interval= 20)
plt.show();
【问题讨论】:
-
请提供
trajectory和position的数据 -
我的轨迹是一个列表,它的元素都是列表(长度为2),就像[[2.5,2], [4,3.5], [2,6]....]我的位置是一个ndarray,它的元素都是元组(长度为2),就像((3,5),(6,7)......)轨迹的长度比位置的长得多,因为position 是轨迹的采样点的所有点。轨迹是整个轨迹的所有点。所以,我需要把轨迹上的所有点都画出来,把位置的点分散开@Zephyr
标签: python matplotlib animation data-visualization visualization