python画一个点_通过移动通过散点绘制的点来使python pyplot...

我在用Python制作动画时遇到麻烦.我的问题是为沿特定轨迹移动的3D点设置动画.我可以通过使用动画模块来做到这一点,并在每一帧都重新制作情节(请参阅脚本中的第一个选项).相反,我想只在每个帧上移动点位置,而不重新制作所有轴(请参见脚本中的第二个选项).这是我的脚本:

import numpy as np

import matplotlib.pyplot as plt

import matplotlib.animation as an

from mpl_toolkits.mplot3d import Axes3D

# create the parametric curve

t=np.arange(0, 2*np.pi, 2*np.pi/100)

x=np.cos(t)

y=np.sin(t)

z=t/(2.*np.pi)

# create the figure

fig=plt.figure()

ax=fig.gca(projection='3d')

# create the first plot

point=ax.scatter(x[0], y[0], z[0])

line=ax.plot(x, y, z, label='parametric curve')

ax.legend()

ax.set_xlim([-1.5, 1.5])

ax.set_ylim([-1.5, 1.5])

ax.set_zlim([-1.5, 1.5])

# first option - remake the plot at every frame

def update_axes(n, x, y, z, ax):

ax.cla()

ax.set_xlim([-1.5, 1.5])

ax.set_ylim([-1.5, 1.5])

ax.set_zlim([-1.5, 1.5])

point=ax.scatter(x[n], y[n], z[n])

line=ax.plot(x, y, z, label='parametric curve')

ax.legend()

return point

ani=an.FuncAnimation(fig, update_axes, 99, fargs=(x, y, z, ax))

# second option - move the point position at every frame

def update_point(n, x, y, z, point):

point.set_3d_properties(x[n], 'x')

point.set_3d_properties(y[n], 'y')

point.set_3d_properties(z[n], 'z')

return point

#ani=an.FuncAnimation(fig, update_point, 99, fargs=(x, y, z, point))

# make the movie file demo.mp4

writer=an.writers['ffmpeg'](fps=20)

dpi = 100

ani.save('demo.mp4',writer=writer,dpi=dpi)

如果选择第二个选项(注释第一个FuncAnimation并取消注释第二个选项),则我的点仅沿z方向移动.我应该怎么做才能在x和y方向上移动任何建议?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值