-
Notifications
You must be signed in to change notification settings - Fork 101
/
3D_Solar_System_Viewer.py
41 lines (32 loc) · 1.07 KB
/
3D_Solar_System_Viewer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Define the solar system data
data = {
'Name': ['Sun', 'Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'],
'Type': ['Star', 'Planet', 'Planet', 'Planet', 'Planet', 'Planet', 'Planet', 'Planet', 'Planet'],
'x': [0, 0.39, 0.72, 1.0, 1.52, 5.20, 9.58, 19.18, 30.07],
'y': [0, 0, 0, 0, 0, 0, 0, 0, 0],
'z': [0, 0, 0, 0, 0, 0, 0, 0, 0]
}
# Create a DataFrame from the data
df = pd.DataFrame(data)
# Create a figure and a 3D subplot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Plot the Sun
sun = df[df['Name'] == 'Sun']
ax.scatter(sun['x'], sun['y'], sun['z'], s=500, c='yellow', label='Sun')
# Plot the planets
planets = df[df['Type'] == 'Planet']
ax.scatter(planets['x'], planets['y'], planets['z'], s=50, c='blue', label='Planets')
# Set the axis labels
ax.set_xlabel('X (AU)')
ax.set_ylabel('Y (AU)')
ax.set_zlabel('Z (AU)')
# Set the title
ax.set_title('Solar System')
# Add a legend
ax.legend()
# Show the plot
plt.show()