import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation
planets = { "Mercury": {"radius": 0.39, "period": 88}, "Venus": {"radius": 0.72, "period": 225}, "Earth": {"radius": 1.0, "period": 365}, "Mars": {"radius": 1.52, "period": 687}, }
fig, ax = plt.subplots(figsize=(6, 6)) ax.set_facecolor("black") ax.set_aspect("equal") ax.axis("off")
ax.plot(0, 0, 'yo', markersize=20, label='Sun')
planet_plots = {} for name, data in planets.items(): planet_plots[name], = ax.plot([], [], 'o', label=name)
for data in planets.values(): orbit = plt.Circle((0, 0), data["radius"], color="white", fill=False, linestyle="--", alpha=0.3) ax.add_patch(orbit)
ax.set_xlim(-2, 2) ax.set_ylim(-2, 2) ax.legend(loc="upper right")
def update(frame): for name, data in planets.items(): angle = 2 * np.pi * frame / data["period"] x = data["radius"] * np.cos(angle) y = data["radius"] * np.sin(angle) planet_plots[name].set_data(x, y) return planet_plots.values()
ani = FuncAnimation(fig, update, frames=1000, interval=30, blit=True) plt.show()