Make a 3D interactive diagram of the solar system with the real planets of the solar system
Drop files here
or click to upload
import streamlit as st
import pydeck as pdk
import pandas as pd
import numpy as np
# Define the planets data
planets = pd.DataFrame({
'Planet': ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'],
'Distance_from_Sun_AU': [0.39, 0.72, 1.0, 1.52, 5.2, 9.58, 19.22, 30.05],
'Size': [0.383, 0.949, 1.0, 0.532, 10.97, 9.14, 3.98, 3.83] # Relative sizes
})
# Calculate positions in 3D space
planets['x'] = planets['Distance_from_Sun_AU'] * np.cos(np.linspace(0, 2 * np.pi, len(planets)))
planets['y'] = planets['Distance_from_Sun_AU'] * np.sin(np.linspace(0, 2 * np.pi, len(planets)))
planets['z'] = np.zeros(len(planets)) # Assuming a flat layout
# Create the layer
layer = pdk.Layer(
'ScatterplotLayer',
data=planets,
get_position='[x, y, z]',
get_radius='Size * 500', # Scale the size for visibility
get_color='[200, 30, 0, 160]', # Color of the planets
pickable=True,
)
# Set the initial view state
view_state = pdk.ViewState(
longitude=0,
latitude=0,
zoom=2,
pitch=40,
)
# Create the deck
r = pdk.Deck(
layers=[layer],
initial_view_state=view_state,
map_style='mapbox://styles/mapbox/light-v10',
)
st.pydeck_chart(r)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?