这个问题是因为在更新卫星位置时,使用了错误的方法来更新卫星的位置信息。正确的方法是更新卫星的坐标数组,而不是直接更新卫星对象的位置。

以下是修复代码中的问题的示例:

# 添加交互操作
def update_orbits(frame):
    for name, satellite in data.items():
        orbit_radius = satellite['orbit_radius']
        orbit_speed = satellite['orbit_speed']

        # 更新卫星位置
        angle = orbit_speed * frame
        x = orbit_radius * 1.5 * 0.8 * (1.5 * 0.8) ** angle
        y = orbit_radius * 0.8 * (0.8) ** angle
        ax.collections[name]._offsets3d = ([x], [y], [0])

# 动画效果
frames = 100
anim = FuncAnimation(fig, update_orbits, frames=frames, interval=50, repeat=True)

plt.legend()
plt.show()

这样,应该就能够正确地更新卫星的位置并播放动画了

import matplotlibpyplot as pltfrom mpl_toolkitsmplot3d import Axes3Dfrom matplotlibanimation import FuncAnimation# 创建木星及其卫星的数据data = Jupiter radius 69911 color orange orbit_r

原文地址: https://www.cveoy.top/t/topic/hy6x 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录