Reputation: 1
I am trying to plot the orbit of a satellite around earth and the moon after using a RK4 numerical integration method for the orbital motions. But i dont quite know how display this or create the image. I kindly ask if anyone knows how this can be done. Below is the code section for the plotting;
from matplotlib import pyplot as plt
# We only plot the x, y components (view on the ecliptic plane)
x, y, v_x, v_y, t = Orbit(x_0, y_0, v_x0, v_y0, tmin, tmax, N)
kinetic_energy, potential_energy, total_energy = Energy(x,y,v_x,v_y)
# Set a dark background... since... space is dark
plt.style.use('dark_background')
# Create a figure and ax
fig, ax = plt.subplots(figsize=(12, 8))
# Create a yellow circle that represents the Sun, add it to the ax
Earth_circ = plt.Circle((0.0, 0.0), R_E, color='yellow', alpha=0.8)
ax.add_artist(Earth_circ)
# Plot the SSB movement
ax.plot(x, y, ls='solid', color='royalblue')
# Set some parameters for the plot, set an equal ratio, set a grid, and set
# the x and y limits
ax.set_aspect('equal')
ax.grid(True, linestyle='dashed', alpha=0.5)
# Set Axes limits to trajectory coordinate range, with some padding
xmin, xmax = min(x), max(x)
ymin, ymax = min(y), max(y)
dx, dy = xmax - xmin, ymax - ymin
PAD = 0.05
ax.set_xlim(xmin - PAD*dx, xmax + PAD*dx)
ax.set_ylim(ymin - PAD*dy, ymax + PAD*dy)
# Some labelling
ax.set_xlabel('X in Earths-Radius')
ax.set_ylabel('Y in Earths-Radius')
# Saving the figure in high quality
plt.tight_layout()
plt.savefig('orbit.png', dpi=300)
plt.show()
Upvotes: 0
Views: 974