Distance between Earth, Moon and Sun in 3D – Python
import plotly.express as px # Set the sizes and distances for the Sun, Earth, and Moon (in kilometers) sun_radius = 696340 # Radius of the Sun earth_radius = 6371 # Radius of the Earth moon_radius = 1737.4 # Radius of the Moon earth_distance = 1470.98 # Distance from the Sun to Earth (scaled down by a factor of approximately 1/100) moon_distance = 38.44 # Distance from Earth to the Moon (scaled down by a factor of approximately 1/100) # Create a 3D scatter plot fig = px.scatter_3d(x=[0, earth_distance, earth_distance + moon_distance], y=[0, 0, 0], z=[0, 0, 0], color=['Sun', 'Earth', 'Moon'], text=['Sun', 'Earth', 'Moon'], size=[sun_radius, earth_radius, moon_radius]) # Add labels to the data points fig.update_traces(textposition='bottom center', textfont_size=14) # Set the layout of the graph fig.update_layout(scene=dict(aspectmode="auto"), scene_xaxis_title="X (km)", scene_yaxis_title="Y (km)", scene_zaxis_title="Z (km)") # Save the graph as an HTML file fig.write_html("solar_system.html")