import matplotlib.pyplot as plt from numpy import linspace, sin, cos, pi period = { "mercury": 87.96926, "venus": 224.7008, "earth": 365.25636, "mars": 686.97959, "ceres": 1680.22107, "jupiter": 4332.8201, "saturn": 10755.699, "uranus": 20687.153, "neptune": 60190.03, } dist = lambda T: T ** (2 / 3) # Kepler def plot_orbit(planet1, planet2, periods=10): T1 = period[planet1] T2 = period[planet2] d1 = dist(T1) d2 = dist(T2) theta = linspace(0, 2 * pi * periods, 1000) x = d1 * cos(T2 * theta / T1) - d2 * cos(theta) y = d1 * sin(T2 * theta / T1) - d2 * sin(theta) plt.gca().set_aspect("equal") plt.axis("off") plt.plot(x, y) plt.show() plot_orbit("venus", "earth", 8) plot_orbit("jupiter", "saturn", 4) plot_orbit("uranus", "earth", 57) plot_orbit("mercury", "venus", 9)