You can plot single points for Earth and Mars, and then update each point's position to the current frame coordinates.
import matplotlib.pyplot as plt
import matplotlib.animation as animation
earthx = planetRs[0][0]
earthy = planetRs[0][1]
marsx = planetRs[2][0]
marsy = planetRs[2][1]
fig, ax = plt.subplots()
line1, = ax.plot([], [], 'bo', label='Earth') # Earth
line2, = ax.plot([], [], 'ro', label='Mars') # Mars
ax.set(xlim=[-2, 2], ylim=[-2, 2], xlabel='X position', ylabel='Y position')
ax.legend()
ax.grid(False)
def init():
line1.set_data([], [])
line2.set_data([], [])
return line1, line2
def update(frame):
line1.set_data(earthx[frame], earthy[frame])
line2.set_data(marsx[frame], marsy[frame])
return line1, line2
ani = animation.FuncAnimation(
fig, update,
frames=len(earthx),
init_func=init,
interval=30,
blit=True,
)
plt.close()
ani