3D Map of 6 Nearest Stars to Earth Using Python and Claude.ai
by matt392 in Circuits > Software
9 Views, 0 Favorites, 0 Comments
3D Map of 6 Nearest Stars to Earth Using Python and Claude.ai
.png)

3D Map of 6 Nearest Stars to Earth Using Python and Claude.ai. Created basic codebase with Claude, then modified the colors and fonts to make it more readable.
Downloads
Python Code
.png)
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Data - selecting only the 6 closest stars (highest parallax)
names = ['Proxima Centauri', 'Barnard\'s Star', 'Lalande 21185',
'van Maanen\'s Star', 'Ross 248', 'Wolf 359']
ra = np.array([217.39232147200883, 269.44850252543836, 164.10319030755974,
165.83095967577933, 101.28662552099249, 24.771554293454546])
dec = np.array([-62.67607511676666, 4.739420051112412, 7.002726940984864,
35.948653032660104, -16.720932526023173, -17.948299887129313])
parallax = np.array([768.0665391873573, 546.975939730948, 415.17941567802137,
392.75294543876464, 374.48958852876103, 367.71189618147696])
# Convert to 3D coordinates
distances_parsecs = 1000/parallax # Convert parallax to parsecs
distances = distances_parsecs * 3.26156 # Convert parsecs to light years
ra_rad = np.radians(ra)
dec_rad = np.radians(dec)
x = distances * np.cos(dec_rad) * np.cos(ra_rad)
y = distances * np.cos(dec_rad) * np.sin(ra_rad)
z = distances * np.sin(dec_rad)
# Create 3D plot
fig = plt.figure(figsize=(12, 12))
ax = fig.add_subplot(111, projection='3d')
# Plot stars
scatter = ax.scatter(x, y, z, c='gold', s=100)
# Add Sun at origin
ax.scatter(0, 0, 0, color='gold', s=400, label='Sun')
# Add "Sun" text right next to the point (you can adjust the 0.2 offset values to position the text)
ax.text(0.2, 0.2, 0.2, 'Sun', fontsize=10, color='black', weight='bold')
# Add labels for each star with offset
x_offset = 0.1 # Adjust these values to control the label position
y_offset = 0.1
z_offset = 0.1
for i, name in enumerate(names):
ax.text(x[i] + x_offset, y[i] + y_offset, z[i] + z_offset, name, fontsize=12)
# Customize the plot
ax.set_xlabel('X (light years)')
ax.set_ylabel('Y (light years)')
ax.set_zlabel('Z (light years)')
plt.title('Six Closest Stars to Earth', pad=20)
# Add grid
ax.grid(True)
# Add legend
plt.legend()
# Make the plot more interactive by setting equal aspect ratio
ax.set_box_aspect([1,1,1])
plt.show()