Jupiter and its Moons: 3D Visualization of Orbital Paths
This code demonstrates how to visualize the orbital paths of Jupiter and its four largest moons (Io, Europa, Ganymede, and Callisto) using the NASA HORIZONS system.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from astroquery.jplhorizons import Horizons
# 从NASA HORIZONS系统中获取木星的轨道数据
obj = Horizons(id='5', location='@sun', epochs={'start':'2022-01-01', 'stop':'2022-12-31', 'step':'1d'}, id_type='majorbody')
eph = obj.ephemerides()
# 提取木星的位置和速度数据
jupiter_pos = np.array([eph['x'], eph['y'], eph['z']])
jupiter_vel = np.array([eph['vx'], eph['vy'], eph['vz']])
# 获取木卫一至木卫四的轨道数据
moons = ['Io', 'Europa', 'Ganymede', 'Callisto']
moon_pos = []
moon_vel = []
for moon in moons:
obj = Horizons(id=moon, location='@5', epochs={'start':'2022-01-01', 'stop':'2022-12-31', 'step':'1d'}, id_type='majorbody')
eph = obj.ephemerides()
moon_pos.append([eph['x'], eph['y'], eph['z']])
moon_vel.append([eph['vx'], eph['vy'], eph['vz']])
# 创建交互式可视化
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_title('Jupiter and its Moons')
# 绘制木星轨道
ax.plot(jupiter_pos[0], jupiter_pos[1], jupiter_pos[2], label='Jupiter')
# 绘制木卫一至木卫四的轨道
for i in range(len(moons)):
ax.plot(moon_pos[i][0], moon_pos[i][1], moon_pos[i][2], label=moons[i])
# 设置坐标轴标签
ax.set_xlabel('X [AU]')
ax.set_ylabel('Y [AU]')
ax.set_zlabel('Z [AU]')
# 添加图例
ax.legend()
# 显示可视化
plt.show()
This code retrieves orbital data for Jupiter and its four largest moons from the NASA HORIZONS system. The data is then plotted in a 3D visualization, showcasing the orbital paths of these celestial bodies.
Note: This code assumes you have the required libraries installed (numpy, matplotlib, mpl_toolkits, astroquery). If you don't have them, you can install them using pip: pip install numpy matplotlib mpl_toolkits astroquery.
原文地址: https://www.cveoy.top/t/topic/o1R4 著作权归作者所有。请勿转载和采集!